1. Matt Chaput
  2. whoosh
  3. Issues
Issue #252 resolved

Possible bug in query parsing?

Anonymous created an issue

Originally reported to django-haystack: https://github.com/toastdriven/django-haystack/issues/564

Daniel Lindsley thought that it looked like a query parsing bug rather than a query generation bug.

I recently ran into this while trying to figure out why a test case was failing on Whoosh. Here's the test data:

{{{ pk | watch_count | categories -- | ----------- | ---------- 1 | 5 | [1] 2 | 4 | [1] 3 | 3 | [1] 4 | 20 | [] 5 | 0 | [1] }}}

And here's the code I'm running: {{{


from haystack.query import SearchQuerySet from haystack.backends import SQ x = ~SQ(watch_count=0) y = SQ(categories=1) z = SearchQuerySet().filter(x&y) z.query.build_query() u'(NOT (watch_count:0) AND categories:1)' z [<SearchResult: localtv.video (pk=u'5')>] z = SearchQuerySet().filter(y&x) z.query.build_query() u'(categories:1 AND NOT (watch_count:0))' z [<SearchResult: localtv.video (pk=u'3')>, <SearchResult: localtv.video (pk=u'2')>, <SearchResult: localtv.video (pk=u'1')>] }}}

As you can see, even though the logic should be identical, x-before-y and y-before-x return completely different results. (y-before-x returns the correct results.) I'm not sure whether this is a whoosh bug in query parsing or a haystack bug in whoosh query generation.

Comments (3)

  1. Matt Chaput repo owner

    Sorry, this was a dumb bug in the regex for the NOT operator in the parser. It only recognized the "NOT" if it was at the start of the string or after a space (so "(NOT" didn't work).

  2. Log in to comment