Django-haystack: the best ways to create search indexes for models with foreign key and many-to-many fields

Suggestions needed to create more efficient and effective search indexes for models with foreign key and many-to-many fields when 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) 
+7
source share
1 answer

you do not need to declare

 metadata = models.ManyToManyField(MetaData) 

instead, using a loop in an index template is easy where best practices speak in the document

Related data

Linked data is somewhat problematic, as most search engines work better with documents than with relationships. One way to get closer to this is to de-normalize the associated child or objects in the parent document template. Including external relevant data or a simple templatetag Django template {% for %} to iterate over related objects can increase the significant data in your document. Be careful what you include and how you structure it, as this can have consequences for how well the result can be ranked in your search.

http://docs.haystacksearch.org/dev/best_practices.html?highlight=loop

+5
source

All Articles