如何将相关数据添加到 haystack 模型索引中?
我已将 haystack 搜索添加到我刚刚起步的 django 应用程序中,并使用模板功能设法为模型创建索引。由于某种原因,我无法将相关数据添加到此模板索引中。我正在尝试以下操作:
{{object.name}}
{% for tag in object.tags.all %}
{{tag.name}}
{% endfor %}
索引已正确添加,并且我在 object.name 属性上获得搜索结果,但在相关标签上却没有。我通过在普通页面模板中使用相同的模板结构并验证 tag.name 值是否输出到屏幕来验证关系是否正确。
如何调试索引创建?我目前使用简单的搜索后端,因此我相信索引存在于内存中。
这是我的 search_indexes.py
from data.models import VendingMachine
from haystack.indexes import *
from haystack import site
class VendingMachineIndex(SearchIndex):
text = CharField(document=True, use_template=True)
site.register(VendingMachine, VendingMachineIndex)
,有问题的文件名为 vendingmachine_text.txt ,位于 templates/search/indexes/data/ ,其中 data 是应用程序名称。
I have added haystack search to my fledgling django app and managed to create an index for a model, using the template feature. For some reason I am having trouble adding related data to this template index. I am trying the following:
{{object.name}}
{% for tag in object.tags.all %}
{{tag.name}}
{% endfor %}
The indexes are added correctly and I get search results on the object.name property, but not on the related tags. I have verified that the relationships are correct by using the same template structure in a normal page template and verifying that the tag.name values are output to the screen.
How do I go about debugging the index creation? I am using the simple search backend for the moment so I believe the index exists in memory.
Here is my search_indexes.py
from data.models import VendingMachine
from haystack.indexes import *
from haystack import site
class VendingMachineIndex(SearchIndex):
text = CharField(document=True, use_template=True)
site.register(VendingMachine, VendingMachineIndex)
And the file in question is called vendingmachine_text.txt and lives at templates/search/indexes/data/ where data is the app name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题出在“简单”搜索后端。它是新的,仅适用于伪造搜索功能。尝试使用 whoosh、sorl 或 xapian。
我看过
haystack/backends/simple .py
。该后端基于 ORM,并且没有内存中搜索索引。仅按模型字段搜索才有效。I think the problem is in "simple" search backend. It's new and is only good for faking search functionality. Try with whoosh, sorl or xapian.
I've looked at
haystack/backends/simple.py
. This backend is ORM-based and it has no in-memory search index. Only search by model fields will work.