Adding custom index in Sitecore 7.2

adminSitecore0 Comments

Add custom lucene index in Sitecore 7.2 tooked me few hours to understand how to configure that. Following are the some easy step to create custom index using some default index settings. 

Create sitcore patch files with in app_config/include folder. In patch file there will be two sections i.e. first indexConfigurations and second is adding custom index

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <contentSearch>

            <indexConfigurations>
                <customLuceneIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
                    <!-- update values as required -->
                    <indexAllFields>true</indexAllFields>
                    <initializeOnAdd>true</initializeOnAdd>


                    <!-- START: this is the main section tooked few hours to understand -->
                    <!-- reference sections from DefaultIndexConfiguration -->
                    <analyzer ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/analyzer" />
                    <fieldReaders ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/fieldReaders" />
                    <indexFieldStorageValueFormatter ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/indexFieldStorageValueFormatter" />
                    <indexDocumentPropertyMapper ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/indexDocumentPropertyMapper" />
                    <documentBuilderType ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/documentBuilderType" />
                    <!-- END: this is the main section tooked few hours to understand -->
                    
                    <!-- configure fieldMap -->
                    <fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
                        <fieldNames hint="raw:AddFieldByFieldName">
                            <field fieldName="title" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
                            </field>
                        </fieldNames>
                    </fieldMap>
                </customLuceneIndexConfiguration>
            </indexConfigurations>
            
            <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
                <indexes hint="list:AddIndex">
                    <index id="customIndex_master" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
                        <param desc="name">$(id)</param>
                        <param desc="folder">$(id)</param>
                        <!-- This initializes index property store. Id has to be set to the index id -->
                        <param desc="propertyStore" ref="contentSearch/databasePropertyStore" param1="$(id)" />
                        <!-- set reference to customLuceneIndexConfiguration -->
                        <configuration ref="contentSearch/indexConfigurations/customLuceneIndexConfiguration" />
                        <strategies hint="list:AddStrategy">
                            <!-- NOTE: order of these is controls the execution order -->
                            <strategy ref="contentSearch/indexUpdateStrategies/syncMaster" />
                        </strategies>
                        <commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
                            <policies hint="list:AddCommitPolicy">
                                <policy type="Sitecore.ContentSearch.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
                            </policies>
                        </commitPolicyExecutor>
                        
                        <locations hint="list:AddCrawler">
                            <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                                <!-- change database and root as required -->
                                <Database>master</Database>
                                <Root>/sitecore</Root>
                            </crawler>
                        </locations>
                        
                    </index>
                </indexes>
            </configuration>
        </contentSearch>

    </sitecore>
</configuration>

 

Leave a Reply

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