New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
changed behaviour for __contains queries and multiple words in search-term #39
Comments
__contains
queries and multiple words in search-term
__contains
queries and multiple words in search-term
@codingjoe could you make a call on which direction you do want to go? I'm happy to provide a PR, if you also see this as bug |
OK, how about we replicate the same behavior that |
@codingjoe one question, thinking about this:
So, when the goal is to be more similar to the django admin search, I would have to revert the change in 07054b2. Or should I only fix the |
I don't want to just revert the commit, since it added tests, which are great even if they test for the wrong thing. I will create a patch really quick. |
Different to before we now match search terms only if all bits match or the entire statement. The last part differs from the behavior in Django admin, which does not inlcude exact machtes of the entire search term inlcude spaces. Partially revert 07054b2
Different to before we now match search terms only if all bits match or the entire statement. The last part differs from the behavior in Django admin, which does not inlcude exact machtes of the entire search term inlcude spaces. Partially revert 07054b2
@codingjoe I'm happy to help if there is anything I can do |
You can review #40 |
@codingjoe you mean #43 ? |
yes ;) |
I'm creating this as a bug, while of course this could be also an intentional (breaking) change to the library. If that's the case I would work around it.
Beginning with version
7.6.0
there was a change in search behaviour, originating in in this commit.The example is
search_fields = {'title__icontains'}
andModelSelect2Widget
as base for the widgetNow I'm searching for two separate words.
The old behavior (
7.5.0
and earlier) was that both words needed to be in the title, so the term was split into the words, while combining the resulting two__icontains
searches withAND
. So in the result for the selectbox we only get the records which contain both words in the title.New behaviour since
7.6.0
is different, here we also split, but the searches are combined withOR
.So in the result we have all records that have either one OR the other word in the title
Expected behavior
I would have expected the search-results to be the same. While I understand the breaking change in the release, I don't see why this specific behaviour was changed.
When we take the default django-admin-search as an example (also the base for
autocomplete_fields
), we find:https://github.com/django/django/blob/3668da8de821fcb4ddd83fb50a1f04aa02600894/django/contrib/admin/options.py#L1020-L1030
Which means, django admin also does:
possible solution
If you see this also as a bug, I'm happy to work on a fix for it. Otherwise I would try to work around this behaviour.
The text was updated successfully, but these errors were encountered: