[Answered ]-Django Haystack select which fields to search

1👍

You can use AutoQuery instead of the standard filter:


from haystack.inputs import AutoQuery


SearchQuerySet().filter(first_name=AutoQuery('foo'))

https://django-haystack.readthedocs.io/en/v2.4.1/inputtypes.html#autoquery

EDITED
In order to run OR query with "haystack" use SQ objects:

from haystack.backends import SQ
from haystack.inputs import AutoQuery

SearchQuerySet().filter(
    SQ(first_name=AutoQuery('foo')) | SQ(last_name=AutoQuery('foo'))
)

https://django-haystack.readthedocs.io/en/v2.4.1/searchquery_api.html#sq-objects

👤Tonio

Leave a comment