Adding computed field to specific Sitecore 8 Solr index

It's simple enough to add a computed field to the list of default index fields, and therefore all indexes - a patch file containing the following will achieve this:

    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
        <sitecore>
            <contentSearch>
                <indexConfigurations>
                    <defaultSolrIndexConfiguration>
                        <fields hint="raw:AddComputedIndexField">
                            <field fieldName="urllink" returnType="string">RedMoon.Services.SC.Indexing.ComputedFields.ItemUrl, RedMoon.Services.SC</field>
                        </fields>
                    </defaultSolrIndexConfiguration>
                </indexConfigurations>
            </contentSearch>	  
        </sitecore>
    </configuration>
    

What if we want to just add the extra field to a specific index to keep things streamlined? Firstly, amend the <configuration> element ref attribute in your custom index definition file to point to some custom config elements which we'll define in a separate file in a second - something along the lines of:

    <configuration ref="myCustomIndexNameSearch/indexConfigurations/myCustomIndexNameSolrIndexConfiguration" />
    

Next create the configuration patch file for the index - in keeping with the example set by the index defined by /App_Config/Include/ListManagement/Sitecore.ListManagement.Solr.Index.List.config and its configuration patch file at /App_Config/Include/ListManagement/Sitecore.ListManagement.Solr.IndexConfiguration.config, you may want to name it something along the lines of Sitecore.MyCustomIndexName.Solr.Index.IndexConfiguration.config. In the file create elements which match up to the <configuration> element ref attribute in your custom index definition file, for example:

    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
        <sitecore>		
            <myCustomIndexNameSearch>
                <indexConfigurations>
                    <myCustomIndexNameSolrIndexConfiguration
                        ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration">					
                        <fields hint="raw:AddComputedIndexField">
                            <field fieldName="urllink" returnType="string">RedMoon.Services.SC.Indexing.ComputedFields.ItemUrl, RedMoon.Services.SC</field>
                        </fields>
                    </myCustomIndexNameSolrIndexConfiguration>
                </indexConfigurations>
            </myCustomIndexNameSearch>
        </sitecore>
    </configuration>
    

You can make up the element names to suit - as long as they match up between the two config files.
Note that the above example also brings in the fields from the default configuration.

 


By James at 29 Sep 2015, 21:28 PM


Comments

naga
HI, i have a computed field that reads a reference field say(drop link), and in the computed field we read the values of the reference item Field ,Problem statement: for English the computed field works good but for arbic or some other language the data is getting populated form En only.
12/14/2016 12:22:09 PM

Post a comment