Skip to content

Create a custom index in Sitecore with Docker

Posted in :

rbatallas

Usually, we need to create a custom index for saving save specific content in order to improve our search functionality.

So, let’s take a look on how to do it:

  • Inside this folder Docker\build\solr-init, create a new JSON file called cores-custom.json
  • Add the following content in the file
{
    "sitecore":[
        "_custom_solr_index"
    ]
}

Then in your Visual Studio Solution, inside your Search project or the project you want do the following:

  • Create the following folder structure if not exists
    • App_Config\Include\Search
  • then add the following configutarion file, name the file Sitecore.CustomIndex.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
   <sitecore role:require="Standalone or ContentManagement or ContentDelivery" search:require="solr">
      <contentSearch>
         <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
            <indexes hint="list:AddIndex">
               <!--$(ResourceIndexEnvironmentPrefix): ??-->
               <index id="sitecore_custom_solr_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
                  <param desc="name">$(id)</param>
                  <param desc="core">$(id)</param>
                  <!-- This initializes index property store. Id has to be set to the index id -->
                  <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />

                  <configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration" >
                     <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
                        <indexAllFields>true</indexAllFields>
                     </documentOptions>
                  </configuration>

                  <strategies hint="list:AddStrategy">
                     <!-- NOTE: order of these is controls the execution order -->
                     <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
                  </strategies>

                  <locations hint="list:AddCrawler">
                    <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                      <Database>web</Database>
                      <Root>/sitecore/content/Website/Home</Root>
                    </crawler>
                  </locations>
               </index>
            </indexes>
         </configuration>
      </contentSearch>
   </sitecore>
</configuration>

In this point you can publish your new file to docker

Open the cms in the brower

  • Open Control Panel
  • Go to the indexing section and Populate the new index

and finaly run the indexation process

And that is it.

With these simple steps, you can create a new index personalize the content you want to add on it.

Leave a Reply

Your email address will not be published. Required fields are marked *