I have a computed field called Terms. This field reads the list of guid values that Sitecore stores the multilist field as, into a comma separated string of values. When I trigger an index rebuild and set a breakpoint, I can see the code performing the task as expected, but for some reason, in the index the value is still being stored as an array of guid strings. I don't know where the disconnect is.
Checking Solr and configuring the query to return xml, I can see the terms field being stored like so:
<arr name="terms_t">
<str>b7ba58ef002b4554808a1d423ca574d8</str>
<str>95680bf346d142aeb0d8f189300ea3f2</str>
</arr>
Below You can see the class used to populate the computed field
namespace ASHPEngine.ComputedFields
{
public class Terms : Sitecore.ContentSearch.ComputedFields.IComputedIndexField
{
public object ComputeFieldValue(IIndexable indexable)
{
Assert.ArgumentNotNull(indexable, "indexable");
var scIndexable = indexable as Sitecore.ContentSearch.SitecoreIndexableItem;
if (scIndexable == null)
{
return false;
}
if (String.Compare(scIndexable.Item.Database.Name, "core", System.StringComparison.OrdinalIgnoreCase) == 0)
{
return false;
}
if (!scIndexable.Item.InheritsFrom(IBaseArticleConstants.TemplateName)) return String.Empty;
var termsField = scIndexable.GetFieldByName(INewsConstants.TermsFieldName);
{
var retval = new StringBuilder();
var terms = termsField.Value.ToString().Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
foreach (var id in terms)
{
var termItem = scIndexable.Item.Database.GetItem(new ID(id));
retval.Append(termItem.Name + ", ");
}
return retval.Length > 0 ? retval.Remove(retval.Length-2, 2).ToString() : string.Empty;
}
}
public string FieldName { get; set; }
public string ReturnType { get; set; }
}
And the configuration:
<configuration>
<sitecore>
<contentSearch>
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
<indexes hint="list:AddIndex">
<index id="news" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
<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/indexConfigurations/databasePropertyStore" param1="$(id)" />
<configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration">
<fieldMap ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/fieldMap">
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="_uniqueid" returnType="string" />
<field fieldName="article" returnType="string" />
<field fieldName="author" returnType="string"/>
<field fieldName="author credentials" returnType="string" />
<field fieldName="date" returnType="datetime" format="yyyy-MM-dd'T'HH:mm:ss'Z'" />
<field fieldName="degree" returnType="string" />
<field fieldName="graduation year" returnType="string" />
<field fieldName="location" returnType="string" />
<field fieldName="navigation title" returnType="string" />
<field fieldName="page abstract" returnType="string" />
<field fieldName="school" returnType="string" />
<field fieldName="text" returnType="string" />
<field fieldName="value" returnType="string" />
</fieldNames>
</fieldMap>
<documentOptions ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/documentOptions">
<fields hint="raw:AddComputedIndexField">
<field fieldName="external_link" returnType="text">mydll.ComputedFields.ExternalLink, mydll</field>
<field fieldName="image" returnType="text">mydll.ComputedFields.Image, mydll</field>
<field fieldName="terms" returnType="text">mydll.ComputedFields.Terms, mydll</field>
<field fieldName="url" returnType="text">mydll.ComputedFields.Url, mydll</field>
<field fieldName="parentname" returnType="text">mydll.ComputedFields.ParentName, mydll</field>
</fields>
</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</Root>
</crawler>
</locations>
<enableItemLanguageFallback>false</enableItemLanguageFallback>
<enableFieldLanguageFallback>false</enableFieldLanguageFallback>
</index>
</indexes>
</configuration>
</contentSearch>
</sitecore>
</configuration>