Suggestions needed for creating better and efficient search indexes for models having foreign key and many-to-many fields while using haystack with django.
Sample Model:
class Resource(models.Model):
title = models.CharField(max_length=255)
description = models.TextField(blank=True, null=True)
content = models.ForeignKey(ResourceContent, unique=True)
metadata = models.ManyToManyField(MetaData)
you don't need to declare
metadata = models.ManyToManyField(MetaData)
instead use looping inside index template easy where best practise says in doc
Related data is somewhat problematic to deal with, as most search engines are better with documents than they are with relationships. One way to approach this is to de-normalize a related child object or objects into the parent’s document template. The inclusion of a foreign key’s relevant data or a simple Django {% for %}
templatetag to iterate over the related objects can increase the salient data in your document. Be careful what you include and how you structure it, as this can have consequences on how well a result might rank in your search
http://docs.haystacksearch.org/dev/best_practices.html?highlight=loop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With