django-haystack和Solr拼写建议 [英] Spelling Suggestions with django-haystack and Solr

查看:108
本文介绍了django-haystack和Solr拼写建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到 None的拼写建议。

I'm getting "None" for spelling suggestions.

首先,我在settings.py文件中设置了此设置:

First, I have this set in my settings.py file:

HAYSTACK_INCLUDE_SPELLING = True

我有重建索引:

python manage.py rebuild_index

并进行了很好的更新

python manage.py update_index

搜索正常。当我搜索 Charger时,它返回匹配的结果。因此,在我的views.py中,我然后尝试了以下方法:

The search works correctly. When I search for "Charger", it returns the results that match. So in my views.py, I then tried:

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}}买些东西吗?我缺少什么?

Obviously, I expected nothing for {{ test }}, but shouldn't I get something for {{ spelling_suggestion }}? What am I missing?

推荐答案

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

I did finally figure this out (with some help from the Haystack message group)

有一些详细信息此处关于必须进行的配置更改。另外,我必须在haystack的views.py文件中添加行(在def extra_context下):

There is some detail here on configuration changes that must be made. In addition, I had to add lines to haystack's views.py file (under def extra_context):

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

然后我在输出模板中添加了{{建议}}

Then I added {{ suggest }} to my output template

这篇关于django-haystack和Solr拼写建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆