开发者

django-haystack : Better ways of creating search indexes for models having foreign key and many-to-many fields

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜