Skip to content

Commit 64270d6

Browse files
committed
Fixed the docs on enabling spelling suggestion support in Solr.
1 parent c9a53ea commit 64270d6

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

docs/installing_search_engines.rst

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,24 @@ Spelling Suggestions
4949
--------------------
5050

5151
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
5370
``solrconfig.xml`` file within the ``config`` tag::
5471

5572
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
@@ -58,7 +75,7 @@ enable the ``SpellCheckComponent``. Add the following line to your
5875

5976
<lst name="spellchecker">
6077
<str name="name">default</str>
61-
<str name="field">text</str>
78+
<str name="field">suggestions</str>
6279
<str name="spellcheckIndexDir">./spellchecker1</str>
6380
<str name="buildOnCommit">true</str>
6481
</lst>
@@ -76,10 +93,9 @@ Then change your default handler from::
7693
</arr>
7794
</requestHandler>
7895

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
8097
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``).
8399

84100

85101
Whoosh

docs/searchindex_api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ already present in the quickest and most efficient way.
363363
================
364364

365365
``index_queryset``
366-
----------------
366+
------------------
367367

368368
.. method:: SearchIndex.index_queryset(self)
369369

0 commit comments

Comments
 (0)