Solr Integration with Sitecore

On this page Solr Installation: Generating a XML Schema for Solr Pushing Config file to Zookeeper- Creating new Collections and Alias – Configuring Sitecore to work with Solr Solr specific settings

Solr Installation:

  1. Install JRE if you don’t already have it.
  2. Add a system environment variable called JAVA_HOME that points to your java installation:
    • Variable Name: JAVA_HOME
    • Variable Value (set as necessary): C:\Program Files (x86)\Java\jre1.8.0_77
  1. Install NSSM at C:/nssm (or the directory of your choice). NSSM is a service helper which register the SOLR as a Service so that SOLR will be up every time when system get started
  2. Create and unzip SOLR 5.4.1 into C:/solr
    • NOTE: Remove any intermediary folders to avoid a folder structure like C:/solr/solr-5.4.1/server
    • This should now be a valid path on your file system: C:/solr/server
    • Keep in mind that if you do not install SOLR to this directory, then some automation scripts may require manual intervention and/or passing your solr installation directory as an argument.
    • Copy the conf folder from C:/solr/server/solr/configsets/sample_techproducts_configs/conf to C:/solr folder (can rename conf to config) and check schema.xml and solrconfig.xml is present
  1. Open Powershell and use NSSM to set SOLR up as a service as follows:
    # Use either 64 or 32 bit version according to your computer
    cd C:\nssm\win64
    ./nssm install SOLR
  1. The NSSM Service Installer application window will open. Set the following values:
    • Path: C:\solr\bin\solr.cmd
    • Startup Directory: C:\solr\bin
    • Arguments: start -f -p 8983
    • Display Name: SOLR 5.4.1
    • Description: C:\solr\bin\solr.cmd start -f -p 8983
    • Startup type: Automatic
  1. Open your services and start the newly created SOLR 5.4.1 service.

Generating a XML Schema for Solr

This tool automatically generates a basic schema and ensures all the fields that Sitecore needs are present. You can add your own fields to this schema as long as you do not change the system index fields.

1.      In the Sitecore Desktop, open the Control Panel. In the Control Panel, click Indexing.

2.      Then click Generate the Solr Schema.xml file.

3.      In the Build Schema window, in the Source field, enter the path to the Solr schema that you want to use, for example: ….solr\ conf\schema.xml

In the Target File field, enter the destination for the new schema file, for example the website root folder: ………….\Website\schema.xml

4.      Click Generate.

This updates the schema.xml and adds all the necessary fields that Sitecore needs. When the tool has finished, copy the file to the conf directory in the solr\ conf\ folder

Pushing Config file to Zookeeper-

Run the following command in command prompt (Administrator mode):

server\scripts\cloud-scripts\zkcli.bat -zkhost localhost: 9983 -cmd upconfig -confname -confdir

For Example:

server\scripts\cloud-scripts\zkcli.bat -zkhost localhost:9983 -cmd upconfig -confname solrconfig -confdir C:\Solr\config

For any change in the schema file run the above command

Creating new Collections and Alias –

Browse the Below URLs to create the collection in Solr

http://localhost:8983/solr/admin/collections?action=CREATE&name=Sitecore_Default_Core&numShards=1&replicationFactor=1&collection.configName=solrconfig

http://localhost:8983/solr/admin/collections?action=CREATE&name=Sitecore_Default_Master&numShards=1&replicationFactor=1&collection.configName=solrconfig&wt=xml

http://localhost:8983/solr/admin/collections?action=CREATE&name=Sitecore_Default_Web&numShards=1&replicationFactor=1&collection.configName=solrconfig&wt=xml

similarly we can use the above command to create the multiples of collection for the sitecore locale sites. Ex.-

http://localhost:8983/solr/admin/collections?action=CREATE&name=BrandName_local_search_master_index&numShards=1&replicationFactor=1&collection.configName=solrconfig&wt=xml

http://localhost:8983/solr/admin/collections?action=CREATE&name=BrandName_local_search_web_index&numShards=1&replicationFactor=1&collection.configName=solrconfig&wt=xml

Configuring Sitecore to work with Solr

Enable SOLR in Global.asax file

  1. Navigate to…\Website\Global.asax and open Global.asax file in notepad.
  2. Update Inherits=”Sitecore.Web.Application”        to Inherits=”Sitecore.ContentSearch.SolrProvider.UnityIntegration.UnityApplication”

Put the Supporting DLL files

Put the following support DLLs in the bin directory alongside the DLLs installed.

Microsoft.Practices.ServiceLocation.dll
Microsoft.Practices.Unity.dll
Sitecore.ContentSearch.Linq.Solr.dll
Sitecore.ContentSearch.SolrProvider.dll
Sitecore.ContentSearch.SolrProvider.UnityIntegration.dll
SolrNet.dll
Unity.SolrNetIntegration.dll

Now we need to make the configuration changes in sitecore so that it will use the Solr.
Follow the below steps:

  1. Navigate to the website Include folder: wwwroot\\App_Config\Include\
  2. Disable the following Lucene configuration files by adding .example to the file name extension:
    Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config
    Sitecore.ContentSearch.Lucene.Index.Analytics.config
    Sitecore.ContentSearch.Lucene.Index.Core.config
    Sitecore.ContentSearch.Lucene.Index.Master.config
    Sitecore.ContentSearch.Lucene.Index.Web.config
    Sitecore.ContentSearch.Lucene.Indexes.Sharded.Core.config.example
    Sitecore.ContentSearch.Lucene.Indexes.Sharded.Master.config.example
    Sitecore.ContentSearch.Lucene.Indexes.Sharded.Web.config.example
  3. Enable the Sitecore.ContentSearch.Solr.*.config file by removing .example from the file name.
    Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config.example
    Sitecore.ContentSearch.Solr.Index.Analytics.config.example
    Sitecore.ContentSearch.Solr.Index.Core.config.example
    Sitecore.ContentSearch.Solr.Index.Master.config.example
    Sitecore.ContentSearch.Solr.Index.Web.config.example

Solr specific settings

The following Solr specific settings can be found 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.

solr

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, which was the default setting.

setting name=”ContentSearch.Provider” value=”Solr”

Re-building the Search Indexes

Before you can start using the Solr indexing system you need to re-index all your Sitecore content.

To rebuild the Sitecore search indexes:

  1. Log into the Sitecore Desktop.
  2. Click Start and then click Control Panel.
  3. In Control Panel, select Indexing.
  4. Then select Indexing Manager.
  5. In the Select Search Index window, select all local indexes.
  6. Click Rebuild and then click Finish when the Wizard has completed.
Filed under Search and Indexing
Ravindra Giri
Ravindra Giri

Sr. Sitecore Technical Architect

Leave a Reply

Discover more from Sitecore Nuke

Subscribe now to keep reading and get access to the full archive.

Continue reading