繁体   English   中英

与django-haystack和Solr的拼写建议

[英]Spelling Suggestions with django-haystack and Solr

拼写建议我得到“无”。

首先,我在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}}得到什么? 我错过了什么?

我终于搞清楚了(在Haystack消息组的帮助下)

有一些细节在这里的配置更改必须做出。 另外,我不得不在haystack的views.py文件中添加行(在def extra_context下):

spelling = self.results.spelling_suggestion(self.query)
return {'suggestion': spelling, . . .

然后我将{{suggest}}添加到我的输出模板中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM