Solr includes an autosuggest component, Suggestor. From Solr 4.7 onwards, the
implementation of this Suggestor is changed. The old SpellChecker based
search component is replaced with a new suggester that utilizes Lucene suggester module. The latest Solr download is preconfigured with this new suggester, but the documentation on the Solr wiki is
still of the previous SpellCheck version.
It took me sometime to understand the new suggester and
get it working.
There are two configurations for suggester, a search component and a request handler:
<searchComponent name="suggest"
class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggester</str>
<str
name="lookupImpl">FuzzyLookupFactory</str>
<!-- org.apache.solr.spelling.suggest.fst -->
<str
name="dictionaryImpl">DocumentDictionaryFactory</str>
<!-- org.apache.solr.spelling.suggest.HighFrequencyDictionaryFactory -->
<str name="field">cat</str>
<str name="weightField">price</str>
<str name="suggestAnalyzerFieldType">string</str>
</lst>
</searchComponent>
<requestHandler name="/suggest"
class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="suggest">true</str>
<str name="suggest.count">10</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
The url for getting suggestions
(use suggest.build=true for the first time)
In my case this returns
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">13</int>
</lst>
<str name="command">build</str>
<lst name="suggest">
<lst name="mySuggester">
<lst name="A">
<int name="numFound">2</int>
<arr name="suggestions">
<lst>
<str name="term">A
Clash of Kings</str>
<long name="weight">0</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">A
Game of Thrones</str>
<long name="weight">0</long>
<str name="payload"/>
</lst>
</arr>
</lst>
</lst>
</lst>
</response>
Since a default suggester is not configured, suggest.dictionary is required, without it, you will get an exception: No suggester named default was configured
You can configure default suggestor in the SolrConfig.xml
<requestHandler
name="/suggest" class="solr.SearchHandler"
startup="lazy">
<lst name="defaults">
<str name="suggest">true</str>
<str name="suggest.count">10</str>
<str name="suggest.dictionary">mySuggester</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
Now you should be able to get suggeston, without
having to specify dictionary in the URL.
No comments:
Post a Comment