Spelling Suggestions with django-haystack and Solr

佐手、 提交于 2019-12-10 10:24:29

问题


I'm getting "None" for spelling suggestions.

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

HAYSTACK_INCLUDE_SPELLING = True

I have rebuilt the index:

python manage.py rebuild_index

and updated it for good measure

python manage.py update_index

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
    })

However, my template:

<html>
    <body>

        {{ test }}<p>
        {{ spelling_suggestion }}

    </body>
</html>

Still returns nothing:

[]

None

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


回答1:


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

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



来源:https://stackoverflow.com/questions/4594782/spelling-suggestions-with-django-haystack-and-solr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!