Sunday, 26 February 2017

Part 4: Sitecore 8.2 with SOLR 6.2

Leave a Comment
Hello, Sitecore enthusiasts! This is the fourth article of Sitecore 8.2 with Solr 6.2 blog series.

Create a custom SOLR Core for custom search index

  1. Copy the sitecore_configs (C:\Bitnami\solr-6.2.1-2\apache-solr\server\solr\configsets\sitecore_configs) folder and paste it in C:\Bitnami\solr-6.2.1-2\apache-solr\server\solr. Rename it to the sitecore_custom_master_index. Refer to this blog post for more information.
  2. Navigate to the Solr admin page.
  3. After login, navigate to Core Admin page and click on "Add Core" button.
  4. Fill in the 'name' and 'instanceDir' fields with sitecore_custom_master_index, and press the "Add Core" button to add the core into Solr. 
  5. You should be able to see that sitecore_custom_master_index core is now present in the list of cores available in your Solr instance.
  6. Repeat above steps and add a new core sitecore_custom_web_index.

Create custom index configuration file for custom SOLR core

  1. In our Sitecore project we should first add a custom .config file for our custom SOLR Core. Navigate to /App_Config/Include/ folder and add a new config file and name it as Sitecore.ContentSearch.Solr.Index.Custom.Master.config.
  2. Copy configuration contents from config file Sitecore.ContentSearch.Solr.Index.Master and paste it in newly created config file Sitecore.ContentSearch.Solr.Index.Custom.Master.config
  3. Open Sitecore.ContentSearch.Solr.Index.Custom.Master.config file and make below changes: 
    • Index Id : Index should be the same as it is in SOLR
      <index id="sitecore_custom_master_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
    • Configuration : We’ll need an additional configuration file inside our project for new custom core. This configuration will connect our Sitecore Item and SOLR during rebuilding of indexes. All settings from this configuration file will be taken in during that process. Within the configuration file, you can specify new fields types and computed fields.
      <configuration ref="contentSearch/indexConfigurations/customSolrIndexConfiguration" />
    • Strategies : Here you can specify indexing update strategy.
    • Database : Database which we want to crawl.
      <Database>master</Database>
    • Root : Content root path from where we want to crawl.
      <Root>/sitecore</Root>
  4. Repeat above steps for sitecore_custom_web_index. Update index id as sitecore_custom_web_index and database as web in Sitecore.ContentSearch.Solr.Index.Custom.Web.config file.
  5. We have to create an additional configuration file inside our project for new custom core. Duplicate config file Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config and rename it as Sitecore.ContentSearch.Solr.CustomIndexConfiguration.config. Rename <defaultSolrIndexConfiguration> as <customSolrIndexConfiguration> in configuration file. We can define which templates we want to include in our index, we can add a custom computed field into our index and connect it to a class inside our project. There are a lot of settings in this file and you should customize them to your needs.
  6. The last step is to rebuild our custom index in Sitecore’s Index Manager. Go to Control Panel -> Indexing Manager and rebuild sitecore_custom_master_index and sitecore_custom_web_index.

Key Content Search Settings

Below are the several key settings which you should be aware of when using the Sitecore Content Search layer:
  1. ContentSearch.SearchMaxResults : This controls how many documents are returned to Sitecore when it queries Solr.  The default is 500 documents which is plenty.  Know that requests to Solr are made over HTTP, therefore the more requests you receive, the larger the response payload will be.
  2. ContentSearch.Solr.ServiceBaseAddress : This points to Solr, you should be able to take the value of this setting, paste it in a browser and get directly to Solr.
  3. ContentSearch.Update.BatchModeEnabled : Enabling this will certainly help committing documents to Solr when you are rebuilding or updating an index.
  4. ContentSearch.Update.BatchSize : This is used when the above setting is set to true.
  5. ContentSearch.EnableSearchDebug : Set this to true while you are debugging your search queries. You will also need to make sure log4net is also set to at least DEBUG.

Multiple Solr cores

For optimal performance Sitecore recommends that you always use multiple cores for your indexes. If you store all indexes in the same core, when you update an index the contents of all the other indexes in the same core are also cleared. As it is possible to rebuild indexes individually, some indexes will be left empty after rebuild. If you store each default index in a separate Solr core the names of these cores should match the names of the Sitecore indexes.
Multiple Solr cores may improve the performance of your search and indexing. For example, you should use separate cores for each index in a production environment and only share indexes on a single core in a development environment. The Solr website provides more detailed guidance and advice when configuring Solr.
Related read:
Comments and suggestions are most welcome. Happy coding!
Read More...