Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /homepages/33/d337644085/htdocs/kieron-wp/wp-content/plugins/jetpack/_inc/lib/class.media-summary.php on line 77

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /homepages/33/d337644085/htdocs/kieron-wp/wp-content/plugins/jetpack/_inc/lib/class.media-summary.php on line 87

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /homepages/33/d337644085/htdocs/kieron-wp/wp-content/themes/Divi/includes/builder/functions.php on line 4940
Solr Suggester config example - Kieron Howard
Select Page

I couldn’t seem to get the Solr Suggester feature to work from the official docs examples so thought I’d document my working example.

In my case I wanted to suggest locations based on data currently within the index.

within solrconfig.xml

 

<searchComponent name=”suggest” class=”solr.SpellCheckComponent”>
<lst name=”spellchecker”>
<str name=”name”>suggest</str>
<str name=”classname”>org.apache.solr.spelling.suggest.Suggester</str>
<str name=”lookupImpl”>org.apache.solr.spelling.suggest.tst.TSTLookup</str>
<str name=”field”>myFieldForAutocomplete</str>
</lst>
</searchComponent>

<requestHandler name=”/suggest” class=”org.apache.solr.handler.component.SearchHandler”>
<lst name=”defaults”>
<str name=”spellcheck”>true</str>
<str name=”spellcheck.dictionary”>suggest</str>
<str name=”spellcheck.count”>10</str>
</lst>
<arr name=”components”>
<str>suggest</str>
</arr>
</requestHandler>

and then schema.xml

 

<types>

<fieldType class=”solr.TextField” name=”text_auto”>
<analyzer>
<tokenizer class=”solr.KeywordTokenizerFactory”/>
<filter class=”solr.LowerCaseFilterFactory”/>
</analyzer>
</fieldType>
</types>

and in schema.xml fields:

 

<field name=”myFieldForAutocomplete” type=”text_auto” indexed=”true” stored=”true” multiValued=”false” />
<copyField source=”city” dest=”myFieldForAutocomplete” />

then its a simple case of building the index with a call to:

http://localhost:4569/solr/myCore/suggest?spellcheck.build=true

after that we can use suggest with:

 

http://localhost:4569/solr/myCore/suggest?q=myQuery

Solr should then give you a nice response like:

 

<response>
<lst name=”responseHeader”>
<int name=”status”>0</int>
<int name=”QTime”>1</int>
</lst>
<lst name=”spellcheck”>
<lst name=”suggestions”>
<lst name=”abe”>
<int name=”numFound”>1</int>
<int name=”startOffset”>0</int>
<int name=”endOffset”>3</int>
<arr name=”suggestion”>
<str>aberdeen</str>
</arr>
</lst>
</lst>
</lst>
</response>
%d bloggers like this: