问题
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