Search over multiple fields

孤者浪人 提交于 2019-12-03 21:23:50
vinilios

I guess thats because haystack uses the document field for generic searches unless you define a specific search for other fields like the twitter_account field.

from haystack documentation

Every SearchIndex requires there be one (and only one) field with document=True. This indicates to both Haystack and the search engine about which field is the primary field for searching within.

Try specifing the index as follows

class UserProfileIndex(SearchIndex):
    text = CharField(document=True, use_template=True)
    user = CharField(model_attr='user')
    twitter_account = CharField(model_attr='twitter_account')

and create the a file named search/indexes//userprofile_text.txt

which will contain the following

{{ object.user.get_full_name }}
{{ object.twitter_account}}

now haystack will search in the contents of this file (where you can add whatever you want) when you don't specify an index filter.

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