2017-08-30

Configure SOLR search with Sitecore Experience Accelerator

It's been quite a while since my last update, but today I finally was able to get something to work that gave me so much headache I thought it might help someone else if I'd put my solution in a blog.

The problem was configuring Solr search for our new Sitecore site. Normally, this is supported pretty much out of the box. However this new site also uses the awesome new Experience Accelerator, which throws a wrench into the process. It also doesn't help I wasn't able to find a single blog or Sitecore documentation site that gave a proper step-by-step guide for setting up Solr so I'll also do that here.

1. Setting up Solr itself


Grabbing the Solr package

First, we need to get Solr running. For this, I used a BitNami package. Sadly, Sitecore recommends an older version of Solr (5.1) so you'll have to dig for the right package version since BitNami doesn't maintian an archive page for its packages. Luckily, I've done that for you.

Don't install it just yet though, we'll automate all this in the next step!

SolrCannon

Kam Figy (Kamsar on Github) has created an awesome Powershell script to install Solr , configure it for your Sitecore installation and even generate a config patch file to get Sitecore to use the correct Solr cores. Grab it!

Have a close look at the # Variables section and change everything to your liking.

Schema.xml

Lastly, Solr needs a schema.xml to operate on. This is the only step that will require some manual labor because Sitecore doesn't export a correct schema.xml for indexing your SXA content.

  • First, export one from Sitecore (/sitecore/client/Applications/ControlPanel.aspx -> Generate the Solr Schema.xml file)
  • Next, open the schema.xml and add the following line near the bottom. This will make sure your SXA content is also indexed:
<dynamicField name="*_tm"
    type="text_general"
    indexed="true"
    stored="true"
    multiValued="true"/>

Fire all cannons!

Now put everything from the last steps together in one folder. 

Run SolrCannon and answer "y" to the prompt. This will automatically install the BitNami package and fully configure it with everything you need.

2. Configure Sitecore

Next, Sitecore needs to know we're using Solr.

SolrSwap

Another great script, created by Patrick Perrone, automatically switches existing Sitecore config patch files to Solr.

Run it and enter the root folder of your Sitecore instance. Next, answer "S" to have it switch Sitecore over from the standard Lucene to Solr.

You may have to manually enable [instance root]\Website\App_Config\Include\z.Foundation.Overrides\Sitecore.XA.Foundation.Search.Solr.config and disable the Lucene config.

Solr.config

After running SolrCannon, it generated a file called Solr.config. Put this in [instance root]\Website\App_Config\Include\z.yourfolder. The name of the folder can be to your liking, but it MUST start with z and be alphabetically after z.Foundation.Overrides. This is to ensure this config patch is loaded at the very last by Sitecore.

If you did this step incorrectly you'll recognize it by Sitecore throwing the following error:

Could not create instance of type: Sitecore.ContentSearch.SolrProvider.SwitchOnRebuildSolrSearchIndex. No matching constructor was found.


3. Rebuild your indexes and check for errors

If you did everything correctly, when you rebuild your indexes (/sitecore/client/Applications/ControlPanel.aspx -> Indexing manager -> Rebuild) you should see no errors in the Solr logs and all indexes are rebuilt successfully. 

If Solr logs errors, you can add the missing fields to the schema.xml. Running SolrCannon won't update this in the Solr config folder, so find the schema.xml in [Solr install root]\apache-solr\solr\configsets\[sitename]_configs\conf and replace it with the new schema.xml.

Don't forget to restart the solrApache and solrJetty services or the new schema.xml won't be loaded. Rebuild your indexes.

If all went well your indexing manager window should look like this, with document counts > 0:

Indexing manager success

4. ...?

5. Profit!

Now add a search bar and search results page to your site and you're done!