Solr spellcheck¶
Caution
Solr spellcheck works only if you are using the eContent data provider.
Step 1: Configure Solr core¶
Make sure your Solr core is configured correctly. Restart Solr if you did any changes.
Look for the solrconfig.xml
file inside your Solr core directory:
/solr/server/ez/template/solrconfig.xml
Add the following lines to the requestHandler
named /select
.
1 2 3 4 |
|
Make sure you have also the following element in the XML file:
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
Additional definitions for spellcheck can be configured here, but spellcheck should also work with the default values.
Go to your root directory and execute the following commands:
1 2 |
|
Step 2: Enable spellcheck in configuration¶
Modify SearchBundle/Resources/config/econtent_search.yml
:
1 |
|
Step 3: Define search controller behavior¶
The search engine returns search collation and search term suggestions.
1 2 3 4 5 6 7 8 |
|
$productSearchResult->spellcheckCollation |
(string) The collation text. This is the suggested phrase (should contain the complete phrase if the user searched for more than one term.For example, if user searches for "blac spealer", the collation could be: "black speaker"Collation has text only if it results are not 0. |
$spellcheckCollationResults |
The number of hits of collation search. |
$productSearchResult->spellcheckSuggestedTerms |
An array of suggested words and their hits.Example: black => 99 , spealer => 65 . It is sorted by the number of hits, descending. |
Step 4: Prepare template¶
The following Twig template displays these results:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|