Tutorial :django-haystack: how to access the spelling suggestions on the template?



Question:

I'm trying django-haystack with Solr and HAYSTACK_INCLUDE_SPELLING = True.

How do you access the spelling suggestions on the template (generated by the default SearchView) ?

Edit: another question: Can the Spelling Suggestion find words from the database ? For example, using the default Note model from the haystack doc, and the default SearchView, there is no spelling suggestions when I search the word "Lorm" when the database contains a note called "Lorem ipsum". Is it normal ?

Thanks :-)


Solution:1

If you have the search query set in the template, you can do:

{{ sqs.spelling_suggestion }}  

Look at: http://docs.haystacksearch.org/dev/searchqueryset_api.html#spelling-suggestion

for more details.

For haystack to find the spelling suggestions, the search template should include the field you are looking for. So if you search template includes {{ object.title }} you should be picking up the spelling suggestion.

Maybe you forgot to do

python manage.py update_index  

after you added the lorem note.


Solution:2

{{ suggestion }} should suffice if you are using the default SearchView.

See:

https://github.com/toastdriven/django-haystack/blob/master/haystack/views.py#L118

...to see what is available in the template context.

Hassan is correct in stating that you must update/rebuild your index and that you need the right fields in your search template.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »