haystack multiple field search

喜夏-厌秋 提交于 2019-12-04 12:39:23
Facundo Olano

In your index you should define one field with document=True, which is the document haystack will search on. By convention this field is named text. You add extra fields if you plan to do filtering or ordering on their values.

The way to take several fields in account when you perform a search, is to define the document as a template, and set use_template on your document field. Your Index would look like:

class TDocIndex(SearchIndex):

    text = CharField(document=True, use_template=True)

    #if you plan to filter by person
    personid = IntegerField(model_attr='person__id') 

site.register(TDoc, TDocIndex)

And you'd have a search/indexes/tdoc_text.txt template like:

{{ object.content }}
{{ object.filepath }}
{{ object.person.lastname }}

See this answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!