2👍
You can add as many fields as you want in Haystack/ES, but the only field that will store the text used for search, is the one with document=True
, and for standarization, the default name for this field is "text"
Another file you need to have using Haystack is
templates/search/indexes/project/anymodel_text.txt
And you will add in this file the model fields you want to search for text, this anymodel_text.txt
file should look like:
{{ object.name }}
{{ object.description }}
{{ object.last_name }}
# Or any other field that belongs to your model
And this text will be stored in the field text
you’re asking for
-
The fields you add in this
anymodel_text.txt
doesn’t need to be insearch_indexes.py
, the fields used here belongs to your model, the original:e.g.: If you have a file named description in your model, and you didn’t add it in search_indexes.py, you can use it in your
anymodel_text.txt
to store the text of the original field in the text field of Haystack model -
The fields added in
search_indexes.py
are for Haystack model, and don’t need to exist in your model, you can add new fields. This fields will exists in the SearchQuerySet object when searching