Walkthrough: Setting up Solr

Last updated Monday, November 27, 2017 in Sitecore Experience Platform for Administrator, Developer
Keywords: Search

This walkthrough describes how to set up Solr for use with Sitecore. It does not cover all configuration options available in Solr: it only documents configuration details specific for using Solr in Sitecore.

Follow the instructions in the Solr documentation to install Solr. The Solr website lists resources. The wiki hosted there is especially useful.

Note

You must you use a separate core for each index. This topic on the Solr wiki introduces the multiple core concept.

This walkthrough describes how to:

The Solr support package on GitHub contains support for alternative IoC (Inversion of Control) containers.

Note

Do not make changes directly to the configuration files. Instead, you must create a patch file that performs the required changes during run time.

Populate an XML schema for Solr

Solr uses a defined schema when it works with documents. You can modify an existing schema with the Populate Solr Managed Schema tool. This tool automatically populates Sitecore fields and makes sure all fields that Sitecore needs are present.

You can add more fields to this schema by adding fields to the managed-schema file as long as you do not change the system index fields. We recommend that you only do this after you have populated the Solr schema with the Populate Solr Managed Schema tool. You can use the solr admin schema page to add additional fields.

Follow these steps to populate a Solr schema:

  1. Copy the Solr provided configuration example from the configsets folder into [SOLR_DIR]/server/solr and rename it to the appropriate index name.
  2. Open the managed-schema file under the conf folder of folder created in step 1.
    1. Set the value in <uniqueKey>id</uniqueKey> to _uniqueid.
    2. In the fields section, add field configuration for _uniqueid:

      <field name="_uniqueid" type="string" indexed="true" required="true" stored="true"/>

    3. Save your changes.
  3. Repeat step 1 and step 2 for all indexes.
  4. Start Solr.
  5. Start Sitecore, and go to the Control Panel.
  6. In the Indexing tab, click Populate Solr Managed Schema:

    y

  7. In the Schema Populate window, select the indexes you want to populate:

    b

  8. Click Populate.
  9. In the Control Panel, click Generate

Generate an XML Schema for Solr

It is possible to use manual schemas (the "classic" way) by using a Solr schema.xml file:

  1. In the Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config file, change the value of the ContentSearch.Solr.SolrSchemaClass setting to classic.
  2. Set the <schemaFactory> class to ClassicIndexSchemaFactory in the solrconfig.xml file.

Earlier versions of this topic have more information.

Enable Solr term support

When you implement Solr for use with Sitecore, you must enable term support in the Solr search handler.

The term functionality is built into Solr but is disabled by default. To power the dropdowns in the UI, you must enable the terms component.

To enable Solr term support:

  1. In the solrconfig.xml file, locate the requestHandler node:

    <requestHandler name="/select" class="solr.SearchHandler">

    Inside the requestHandler node, you need to add the following line:

    <bool name="terms">true</bool>

  2. Under the "defaults" node, add the following line:

    <lst name="defaults">

    <str name="echoParams">explicit</str>

    <int name="rows">10</int>

    <str name="df">text</str>

    <bool name="terms">true</bool>

    </lst>

  3. After the "defaults" element, add the following node:

    <arr name="last-components">

    <str>terms</str>

    </arr>

  4. Save your changes.

Verify that Solr is running correctly

After generating a new schema.xml file and updating the solrconfig.xml file, you must verify that Solr runs correctly.

To verify that Solr is running correctly:

  1. Ensure Solr is not running. A full restart is needed so that it loads the new configuration.
  2. Start Solr.
  3. Check the output log files. If there are no errors, then open the Solr administration page.

    To open the administration page, enter the following URL in your browser: http://localhost:8983/solr/admin:

    2

  4. Click Core Admin and then click a core. In this example, there is one core, called itembuckets:

    2

If you can see the Solr administration page and do not get any errors in the log files, then Solr is running correctly.

Configure Sitecore to work with Solr

The following Solr setting is in the Web.config file:

  • Enabling a Search Provider

    This setting tells Sitecore that Solr is enabled and so attempts to connect to the Solr server the next time the index is accessed. If it cannot connect you get an error. To disable, set this back to Lucene.

    <add key="search:define" value="Solr" />

The following Solr settings are in the Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config file:

  • Specifying a Solr Service Address

    This setting tells Sitecore where the Solr server is located. Sitecore appends the core name so only the base address needs to be supplied.

    <setting name="ContentSearch.Solr.ServiceBaseAddress" value="http://localhost:8983/solr" />

  • Maximum Number of Search Results

    This is a global setting found in the Sitecore.ContentSearch.config file.

    This setting contains the maximum number of documents to retrieve on a single request if a limit has not been specified in the query, for example, Take(10). It is important to remember, for performance reasons, when querying how many results will be returned from the query being run and to handle them correctly, for example by using paging.

    <setting name="ContentSearch.SearchMaxResults" value="500" />

  • Enabling Batch Mode

    When an item is indexed the composed document is saved to the search index. When the default Lucene provider is enabled then each write is being flushed to a file on the local disk. When a document is written using the Solr provider the update has to travel over a network.

    2

    When an index is rebuilt a large number of document updates are created, this could result in a lot of network traffic which is not very efficient. Therefore using batch can help to optimize the update process as your indexes grow in size.

    <setting name="ContentSearch.Update.BatchModeEnabled" value="true" />

    <setting name="ContentSearch.Update.BatchSize" value="500" />

    Batch mode (enabled by default) takes these document updates and only flushes to the Solr server when the batch has reached a certain size.

    2

    As your index grows you may want to increase this batch size to get the most out of this process.

Before you can start using the Solr indexing system, you must re-index Sitecore content.

To rebuild the Sitecore search indexes:

  1. In the Control Panel, and click Indexing manager.

    2

  2. Select Select all, and then click Rebuild.

    b

Send feedback about the documentation to docsite@sitecore.net.