The ProductIndex
class is the main thing here. Haystack will use this configuration to index your Product
model according to the fields you have chosen to be indexed and in what way. You can read more about it here.
The template which you have created will be used by this field text = indexes.CharField(document=True, use_template=True)
. In this template we include every important data from model or related models, why? because this is used to perform search query on all data if you don't want to lookup in just one field.
# filtering on single field
qs = SearchQuerySet().models(Product).filter(name=query)
# filtering on multiple fields
qs = SearchQuerySet().models(Product).filter(name=query).filter(description=query)
# filtering on all data where ever there is a match
qs = SearchQuerySet().models(Product).filter(text=query)