Setting up SXA Search Box with Solr Suggest

SXA is AWESOME! One of the features I personally liked is the built-in search functionality that requires minimal configuring and no coding (for most basic cases).

In this blog post I will go through setting up the ‘Search Box’ component with Suggest functionality (predictive).

I’m using Sitecore 9.0.1 with SXA 1.6 and Solr 6.6.2.

Configuring the Search Box component

Suggest functionality is enabled by selecting ‘Show predictions’ in the ‘Suggestion mode’ option of the Search Box component properties.


The ‘Max predictive results count’ is responsible for the number of suggestions retrieved from the index, by default it is set to 5.


The above are the only ‘suggest’ related configurations needed from Sitecore/SXA side.

Configuring Solr for Suggest request

SXA uses both [prefix]_master_index and [prefix]_web_index depending on the context for search components. So the below should be done on both cores.

  1. Navigate to your Solr cores folder (usually: C:\Solr\solr-x.x.x\server\solr\)
  2. Locate and open your master/web core’s folder: [prefix]_master/web_index
  3. Open your solrconfig.xml inside the corefolder/config
  4. Look for the request handlers that already exist in your config file and add the following around the already existing ones:
<searchComponent name="suggest" class="solr.SuggestComponent"> 
 <lst name="suggester"> 
  <str name="name">mySuggester</str> 
  <str name="field">sxacontent_txm</str> 
  <str name="suggestAnalyzerFieldType">string</str> 
  <str name="buildOnStartup">true</str> 

<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy" > 
 <lst name="defaults"> 
  <str name="suggest.dictionary">mySuggester</str>
  <str name="suggest">true</str> 
  <str name="suggest.count">10</str> 
 <arr name="components"> 

Notice that I haven’t specified any ‘lookupImpl’ or ‘dictionaryImpl’ in the search component, so Solr uses the default implementations which requires no additional parameters. You can add your preferred implementations and pass the required parameters.

Also note the ‘field’ name to use for suggestions. I have added the ‘sxacontent_txm‘ which is where SXA indexes most of the page content.

The ‘sxacontent_txm’ is a dynamic field of type text_general which is multivalued, stored and indexed:

<dynamicField name="*_txm" type="text_general" multiValued="true" indexed="true" stored="true"/>

Once you place the new sections into the solrconfig.xml file, save it and then reload the master/web core by going to Solr Admin page > Core Admin, select your master/web core and click on reload. After few seconds the button should light up in green to show that it restarted successfully.

Finally, go to Sitecore and rebuild your index.

Testing Solr’s suggester handler and component:

In order to test that Solr has been configured properly, place the following URL into your browser, edit the core name and hit enter:


If you see a ‘HTTP ERROR 404’ message, this means Solr can’t see your new ‘suggest’ request handler in the selected core. This could be caused by adding the ‘suggest’ section into the wrong core or you have not reloaded your core.

You should instead see something similar to the following:

<lst name=”responseHeader>
<int name=”status>0</int>
<int name=”QTime>1</int>
<lst name=”suggest>
<lst name=”mySuggester”>
<lst name=”a>
<int name=”numFound>1</int>
<arr name=”suggestions>
<str name=”term>admin</str>
<long name=”weight>2</long>
<str name=”payload/>

This means your suggester works just fine.

You may also see no suggestions returned:

<lst name=”responseHeader>
<int name=”status>0</int>
<int name=”QTime>0</int>
<lst name=”suggest>
<lst name=”mySuggester”>
<lst name=”a>
<int name=”numFound>0</int>
<arr name=”suggestions/>

Which means you either have no content data, no data that matches your query or you have not rebuild your index.


Finally, go to your SXA page in preview or normal mode (not edit mode), test it out by typing at least two characters and enjoy!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s