我收到的拼写建议为“无”。
首先,我在 settings.py 文件中设置了这个:
HAYSTACK_INCLUDE_SPELLING = True
我已经重建了索引:
python manage.py rebuild_index
并对其进行了良好的更新
python manage.py update_index
搜索工作正常。当我搜索“充电器”时,它返回匹配的结果。所以在我的views.py中,我尝试了:
from haystack.query import SearchQuerySet
def testpage(request):
test_results = SearchQuerySet().auto_query('Chargr')
spelling_suggestion = test_results.spelling_suggestion()
return render_to_response('testpage.html', {
'test': test_results,
'spelling_suggestion': spelling_suggestion
})
然而,我的模板:
<html>
<body>
{{ test }}<p>
{{ spelling_suggestion }}
</body>
</html>
仍然没有返回任何内容:
[]
None
显然,我对 {{ test }} 没有任何期望,但我不应该为 {{pelling_suggestion }} 得到一些东西吗?我缺少什么?
我终于弄清楚了(在 Haystack 消息组的帮助下)
有一些细节here http://docs.haystacksearch.org/dev/installing_search_engines.html#spelling-suggestions%5d必须进行的配置更改。此外,我必须向 haystacks views.py 文件添加行(在 def extra context 下):
spelling = self.results.spelling_suggestion(self.query)
return {'suggestion': spelling, . . .
然后我将 {{ suggest }} 添加到我的输出模板中
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)