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.
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:
- Populate an XML schema for Solr
- Generate an XML Schema for Solr
- Enable Solr term support
- Verify that Solr is running correctly
- Configure Sitecore to work with Solr
- Rebuild the search Indexes
The Solr support package on GitHub contains support for alternative IoC (Inversion of Control) containers.
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:
- Copy the Solr provided configuration example from the
[SOLR_DIR]/server/solrand rename it to the appropriate index name.
- Open the managed-schema file under the
conffolder of folder created in step 1.
et the value in
- In the
fieldssection, add field configuration for
<field name="_uniqueid" type="string" indexed="true" required="true" stored="true"/>
- Save your changes.
- Repeat step 1 and step 2 for all indexes.
- Start Solr.
- Start Sitecore, and go to the Control Panel.
- In the Indexing tab, click Populate Solr Managed Schema:
- In the Schema Populate window, select the indexes you want to populate:
- Click Populate.
- 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
- In the
Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.configfile, change the value of the
- Set the
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:
- In the
solrconfig.xmlfile, locate the
<requestHandler name="/select" class="solr.SearchHandler">
Inside the requestHandler node, you need to add the following line:
- Under the "defaults" node, add the following line:
- After the "defaults" element, add the following node:
- 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:
- Ensure Solr is not running. A full restart is needed so that it loads the new configuration.
- Start Solr.
- 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:
- Click Core Admin and then click a core. In this example, there is one core, called itembuckets:
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
- 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
- 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.
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.
As your index grows you may want to increase this batch size to get the most out of this process.
Rebuild the search Indexes
Before you can start using the Solr indexing system, you must re-index Sitecore content.
To rebuild the Sitecore search indexes:
- In the Control Panel, and click Indexing manager.
- Select Select all, and then click Rebuild.