@@ -49,7 +49,24 @@ Spelling Suggestions
49
49
--------------------
50
50
51
51
To enable the spelling suggestion functionality in Haystack, you'll need to
52
- enable the ``SpellCheckComponent ``. Add the following line to your
52
+ enable the ``SpellCheckComponent ``.
53
+
54
+ The first thing to do is create a special field on your ``SearchIndex `` class
55
+ that mirrors the ``text `` field, but has ``indexed=False `` on it. This disables
56
+ the post-processing that Solr does, which can mess up your suggestions.
57
+ Something like the following is suggested::
58
+
59
+ class MySearchIndex(indexes.SearchIndex):
60
+ text = indexes.CharField(document=True, use_template=True)
61
+ # ... normal fields then...
62
+ suggestions = indexes.CharField()
63
+
64
+ def prepare(self, obj):
65
+ prepared_data = super(NoteIndex, self).prepare(object)
66
+ prepared_data['suggestions'] = prepared_data['text']
67
+ return prepared_data
68
+
69
+ Then, you enable it in Solr by adding the following line to your
53
70
``solrconfig.xml `` file within the ``config `` tag::
54
71
55
72
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
@@ -58,7 +75,7 @@ enable the ``SpellCheckComponent``. Add the following line to your
58
75
59
76
<lst name="spellchecker">
60
77
<str name="name">default</str>
61
- <str name="field">text </str>
78
+ <str name="field">suggestions </str>
62
79
<str name="spellcheckIndexDir">./spellchecker1</str>
63
80
<str name="buildOnCommit">true</str>
64
81
</lst>
@@ -76,10 +93,9 @@ Then change your default handler from::
76
93
</arr>
77
94
</requestHandler>
78
95
79
- Be warned that the ``<str name="field">text </str> `` portion will be specific to
96
+ Be warned that the ``<str name="field">suggestions </str> `` portion will be specific to
80
97
your ``SearchIndex `` classes (in this case, assuming the main field is called
81
- ``text ``). This should be the same as the ``<defaultSearchField> `` in your
82
- ``schema.xml ``.
98
+ ``text ``).
83
99
84
100
85
101
Whoosh
0 commit comments