I need to integrate spell check mechanism in Django application. I found that Haystack has "Spelling Suggestions" method to use it. So I have installed latest dev version(2.0.0 beta) of haysatck with Django(1.4.1).
I have downloaded apache-solr-3.6.0 and configured as like in doc.
schema.xml
./manage.py build_solr_schema > solr-3.6.0/example/solr/conf/schema.xml
myapps/mysearch_index.py
from haystack import indexes
class MovieIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True,use_template=True)
# other field definition
suggestions = indexes.FacetCharField()
def prepare(self, obj):
prepared_data = super(NoteIndex, self).prepare(obj)
prepared_data['suggestions'] = prepared_data['text']
return prepared_data
solrconfig.xml
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<str name="queryAnalyzerFieldType">textSpell</str>
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">suggestions</str>
<str name="spellcheckIndexDir">./spellchecker</str>
<str name="accuracy">0.7</str>
<str name="buildOnCommit">true</str>
</lst>
</searchComponent>
<requestHandler name="/spell" class="solr.SearchHandler">
<lst name="defaults">
<str name="spellcheck.dictionary">default</str>
<str name="spellcheck.onlyMorePopular">false</str>
<str name="spellcheck.extendedResults">false</str>
<str name="spellcheck.count">1</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
settings.py
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://127.0.0.1:8983/solr',
'TIMEOUT': 60 * 5,
'INCLUDE_SPELLING': True,
},
}
Restart the solr search engine
cd examples/solr
java -jar start.jar
Rebuild the index
python manage.py rebuild_index
# 9905 entries indexed
Testing through django shell
In [1]: from haystack.query import SearchQuerySet
In [2]: len(SearchQuerySet())
Out[3]: 9905
In [4]: sqs = SearchQuerySet().auto_query('spider')
In [5]: suggestion = sqs.spelling_suggestion()
In [6]: print suggestion
None
In [7]:
I have gone though several bolgs and forum and tried of lot of settings, But spelling_suggestion is always None.
Can anyone help me?
Thanks for reading this post