I looked through the docs, and even created some reverse search loops, but I'm still very confused about what these things do in the haystack. Is the search a complete search for the fields you put in your class that inherits indexes.SearchIndex, indexes.Indexable, or reverse text search inside your template? Can someone explain this to me?
In django haystack, you will create a class that determines which fields should be requested (well, as I understand it):
class ProductIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) name = indexes.CharField(model_attr='title', boost=1.75) description = indexes.CharField(model_attr='description') short_description = indexes.CharField(model_attr='short_description') def get_model(self): return Product def index_queryset(self, using=None): """Used when the entire index for model is updated.""" return self.get_model().objects.filter(active=True, published_at__lte=datetime.now())
You will also create a txt template that will do something - I'm not sure what. I know that the search backend will go through this template during the search algorithm.
{{ object.name }} {{ object.description }} {{ object.short_description }} {% for related in object.related %} {{ related.name }} {{ related.description }} {% endfor %} {% for category in object.categories.all %} {% if category.active %} {{ category.name }} {% endif %} {% endfor %}
As you can see, the template has several fields that I do not have in my index class, they will search in the search database. So why are there fields in the index? What are the roles of an index class and an index template? Can someone please explain this to me.
django django-templates django-haystack
user2734679
source share