SearchFilter is doing AND conditions instead of OR #8848
Unanswered
Milutinke92
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
So, I have a model for example:
I wanted to add
SearchFilter
to enable^headline
(startswith) search and@abstract
(full text search).I have an object with:
{"headline": "test headline"}
When request is sent with
?search=test headline
I get no results.Becasue search term is splitted by
, two conditions are created:
[<Q: (AND: ('headline__istartswith', 'test'))>, <Q: (AND: ('headline__istartswith', 'headline'))>]
At this line;
queryset = queryset.filter(reduce(operator.and_, conditions))
conditions are reduced to:(AND: ('headline__istartswith', 'test'), ('headline__istartswith', 'headline'))
Because of this, now filter is saying: give me article, where headline starts with "headline" and headline starts with "test" which cannot happen.
If i changed meantioned line before to:
queryset = queryset.filter(reduce(operator.or_, conditions))
, everything seems to work.Am I doing something wrong, or am I expecting wrong result, or this is not what SearchFilter should do?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions