I've made a computed index field in my solution. The class returns List<string>
from the ComputeFieldValue method and the config patch includes the field within the fieldMap and documentOptions sections of the defaultSolrIndexConfiguration.
I'm following the answer provided here: Solr tokenization to split on semicolon character
My indexer class is as follows:
public class SemicolonDelimitedField : AbstractComputedIndexField
{
public override object ComputeFieldValue(IIndexable indexable)
{
Item item = indexable as SitecoreIndexableItem;
if (item == null)
{
return null;
}
if (item.TemplateID != Templates.Category.ID
&& item.TemplateID != Templates.CommerceProduct.ID)
{
return null;
}
var fieldValue = item[FieldName];
var values = fieldValue?.Split(new[] {";"}, StringSplitOptions.RemoveEmptyEntries);
if (values == null || values.Any() == false)
{
return null;
}
var returnValue = values.Select(v => v.Trim()).ToList();
return returnValue;
}
}
And the config patch is as follows
<?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 search:require="solr">
<contentSearch>
<indexConfigurations>
<defaultSolrIndexConfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider" >
<fieldMap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap, Sitecore.ContentSearch.SolrProvider">
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="myField" returnType="stringCollection" />
</fieldNames>
</fieldMap>
<documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
<fields hint="raw:AddComputedIndexField">
<field fieldName="myField" storageType="NO" indexType="UNTOKENIZED">MyNamespace.SemicolonDelimitedField, MyAssembly</field>
</fields>
</documentOptions>
</defaultSolrIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
</configuration>
What I am seeing in my Solr index is that the computed field does not seem to be breaking up into separate entities in the array e.g.
"myField_sm":["Low level;High level"],
what I was expecting was
"myField_sm":["Low level", "High level"],
I attached the debugger to be 100% sure that a List<string>
with two elements was really being returned. What part of the puzzle am I missing?