2

I am using Solr search for Django application using Haystack. In order to get more precise result, I had to change the search query to perform exact search -

from haystack.query import SearchQuerySet, SQ
from haystack.inputs import Exact

....
query = SQ(tags_indexed=Exact(val.lower()))
sqs = SearchQuerySet().models(
                    SampleModel).filter(query)
...

Now, other way you can do the exact search as mentioned in some documentation is -

query = SQ(tags_indexed__exact=val.lower())

What is the difference between these two?

Sayse
  • 42,633
  • 14
  • 77
  • 146
Mutant
  • 3,663
  • 4
  • 33
  • 53

1 Answers1

1

SQ inherits from django's Q object and will be using djangos exact field lookup.

Exact is a Haystack class that does its own thing. (but most likely ends up at the same query)

The docs state that they are equivalent so it doesn't make much of a difference which you use.

Sayse
  • 42,633
  • 14
  • 77
  • 146
  • Perfect! Thanks for pointing to the link and explanation. The reason why I ask is locally I use whoosh with Haystack and it doesn't give the same result when using __exact vs Exact(). with whoosh using Exact() gives correct result. – Mutant May 25 '16 at 14:50