Hello, Sitecore enthusiasts! This is the fourth article of Sitecore 8.2 with Solr 6.2 blog series.
Comments and suggestions are most welcome. Happy coding!
Create a custom SOLR Core for custom search index
- 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.
- Navigate to the Solr admin page.
- After login, navigate to Core Admin page and click on "Add Core" button.
- Fill in the 'name' and 'instanceDir' fields with sitecore_custom_master_index, and press the "Add Core" button to add the core into Solr.
- 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.
- Repeat above steps and add a new core sitecore_custom_web_index.
Create custom index configuration file for custom SOLR core
- 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.
- 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.
- 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>
- Index Id : Index should be the same as it is in SOLR
- 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.
- 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.
- 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:- 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.
- 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.
- ContentSearch.Update.BatchModeEnabled : Enabling this will certainly help committing documents to Solr when you are rebuilding or updating an index.
- ContentSearch.Update.BatchSize : This is used when the above setting is set to true.
- 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.
Related read:Comments and suggestions are most welcome. Happy coding!
0 comments :
Post a Comment