我得到的拼写建议是"None“。
首先,我在settings.py文件中设置了以下内容:
HAYSTACK_INCLUDE_SPELLING = True我已经重建了索引:
python manage.py rebuild_index并对其进行了更新
python manage.py update_index搜索工作正常。当我搜索"Charger“时,它返回匹配的结果。因此,在我的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 }}没有任何期望,但我不应该为{{ spelling_suggestion }}得到一些东西吗?我遗漏了什么?
发布于 2011-03-16 04:07:47
我最终弄清楚了这一点(在Haystack消息组的帮助下)
关于必须进行的配置更改,有一些详细的here。此外,我还必须在haystack的views.py文件(在def extra_context下)中添加一些行:
spelling = self.results.spelling_suggestion(self.query)
return {'suggestion': spelling, . . .然后我将{{ suggest }}添加到我的输出模板
https://stackoverflow.com/questions/4594782
复制相似问题