3

我得到“无”的拼写建议。

首先,我在我的 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 }} 没有任何期望,但我不应该为 {{ spelling_suggestion }} 得到一些东西吗?我错过了什么?

4

1 回答 1

4

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

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

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

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

于 2011-03-15T20:07:46.897 回答