如何将相关数据添加到干草堆模型索引中? [英] How do I add related data to a haystack model index?

查看:100
本文介绍了如何将相关数据添加到干草堆模型索引中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将干草堆搜索添加到我刚起步的django应用程序中,并使用模板功能设法为模型创建索引.由于某种原因,我无法将相关数据添加到此模板索引中.我正在尝试以下操作:

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 %}

正确添加了索引,但我在object.name属性上获得了搜索结果,但在相关标签上却找不到.通过在普通页面模板中使用相同的模板结构并验证tag.name值是否已输出到屏幕,我已经验证了关系是否正确.

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.

这是我的search_indexes.py

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)

有问题的文件称为vendingmachine_text.txt,位于以下位置:模板/搜索/索引/数据/,其中数据为应用程序名称.

And the file in question is called vendingmachine_text.txt and lives at templates/search/indexes/data/ where data is the app name.

推荐答案

我认为问题出在简单"搜索后端.它是新的,仅适用于伪造搜索功能.尝试使用Whoosh,srl或xapian.

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.

我看过 haystack/backends/simple.py .该后端基于ORM,并且没有内存中搜索索引.仅按模型字段搜索将起作用.

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.

这篇关于如何将相关数据添加到干草堆模型索引中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆