djangosolrdjango-haystacksearchqueryset

What is the difference between using __exact and Exact()?


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?


Solution

  • 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.