django-simple-search icon indicating copy to clipboard operation
django-simple-search copied to clipboard

query = None

Open joej opened this issue 9 years ago • 2 comments

In utils.py, line 17: query = None Any plans for that AND logic? It looks like stub code that didn't get completed.

Details: All return values from build_query() seem to be (OR xxx) structures. So, in the logic flow, I can't see how this chunk of code could ever results in a return of (AND (OR xxxxx), (OR yyyyyy)) -- i.e., Set query to something, and line 30 fires True.

Real example:
Lets say you wanted to search ... but only a subset of Class.objects.all().filter(). Therefore, you'd want to search all their search_fields (e.g., title, description, etc.) for the query_string (e.g., "foo.")

However you want the AND logic to fire so that you can choose a subset (e.g., Class.objects.filter(gender='male') AND <those search_fields, query_string, Q OR construct).

That is where such an "AND" query could be useful. E.g., (AND (acronym__icontains='bar'), (OR xxxx xxx xxx))

joej avatar May 06 '16 19:05 joej

I was wrong:

The query builds multiple ORs, linked by ANDs, when multiple terms are passed in. My bad.

I replaced this logic with python operators, re ran tests while checking the returned 'query' var. I see the AND get built now

code: query = reduce( operator.and_, [ reduce(operator.or_, [Q(**{'%s__icontains' % fld : trm}) for fld in search_fields] for trm in terms ]

joej avatar May 07 '16 18:05 joej

@joej can you post your modified code?

oskarko avatar Dec 20 '16 10:12 oskarko