In the example from http://django-haystack.readthedocs.org/en/latest/tutorial.html
class NoteIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
author = indexes.CharField(model_attr='user')
pub_date = indexes.DateTimeField(model_attr='pub_date')
It says "Every SearchIndex requires there be one (and only one) field with document=True. This indicates to both Haystack and the search engine about which field is the primary field for searching within."
Does this mean it is the same thing as a unique id when it comes to Solr ? It would be really helpful if someone can elaborate with a Solr document example/how it would look like in a query.
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:And this text will be stored in the field
text
you're asking forThe 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 modelThe 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