Create a custom index in Sitecore with Docker

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:

{
    "sitecore":[
        "_custom_solr_index"
    ]
}

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

<?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

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.