How to add text to _content field in Solr index for Sitecore implementation?
This is for the implementation of Sitecore 7.5 - Solr 4.7. I would like to be able to change the text that is stored in the _content field in Solr. I believe that somehow Sitecore is concatenating all the content fields for an element into the _content field in the index. (I think this is correct). At index time, I would like to write my own code that can potentially change the text that is stored in the _content field in Solr. Is it possible? Any ideas how I would go about doing this?
source to share
_content
is a computed field, which means that the value is resolved at the point at which the element is traversed. You will see that the calculated field is defined in your configuration:
<field fieldName="_content" returnType="string" type="Sitecore.ContentSearch.ComputedFields.MediaItemContentExtractor,Sitecore.ContentSearch">
<mediaIndexing ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/mediaIndexing"/>
</field>
I recommend decompiling the class specified in the attribute type
to see what it does. Then you can create your own computed field class (or inherit from it) and replace the type attribute.
Calculated fields are really easy to work with. They implement IComputedIndexField
which method requires ComputeFieldValue
. The method takes a type argument IIndexable
(in most cases the concrete class is Item
) and is called every time the element is traversed.
So, in a method, ComputeFieldValue
you can apply IIndexable
to Item
and then return a concatenated string of all the field values you want to include from this element.
For more information on calculated fields see here:
source to share