django-haystack:为具有外键和多对多字段的模型创建搜索索引的更好方法

时间:2022-11-03 19:34:03

Suggestions needed for creating better and efficient search indexes for models having foreign key and many-to-many fields while using haystack with django.

在使用带有django的haystack时,为具有外键和多对多字段的模型创建更好和更有效的搜索索引所需的建议。

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)

1 个解决方案

#1


5  

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

相关数据有些问题需要处理,因为大多数搜索引擎使用文档比使用关系更好。解决此问题的一种方法是将相关子对象或对象去规范化为父对象的文档模板。包含外键的相关数据或简单的Django {%for%}模板标签来迭代相关对象可以增加文档中的显着数据。请注意包含的内容以及构造方式,因为这会对结果在搜索中的排名产生影响

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

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

#1


5  

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

相关数据有些问题需要处理,因为大多数搜索引擎使用文档比使用关系更好。解决此问题的一种方法是将相关子对象或对象去规范化为父对象的文档模板。包含外键的相关数据或简单的Django {%for%}模板标签来迭代相关对象可以增加文档中的显着数据。请注意包含的内容以及构造方式,因为这会对结果在搜索中的排名产生影响

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

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