开发者

How do I add related data to a haystack model index?

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 t开发者_如何学Cag 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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜