I am trying to create a commuted index field in sitecore 9 but can't get the configuration to work. I have a local environment which is running Solr and also environment is Azure.
I have added the following configuration to my indexing patch config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<indexConfigurations>
<defaultSolrIndexConfiguration>
<fields hint="raw:AddComputedIndexField">
<field fieldName="icon_services" returnType="string">Sitecore.Foundation.Indexing.Infrastructure.Fields.ImageURLComputedField, Sitecore.Foundation.Indexing</field>
</fields>
</defaultSolrIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
</configuration>
This configuration throws the following error:
Server Error in '/' Application. Could not find add method: AddComputedIndexField (type: Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Sitecore.Exceptions.RequiredObjectIsNullException: Could not find add method: AddComputedIndexField (type: Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration)
My code for computed index:
public class ImageURLComputedField : IComputedIndexField
{
public string FieldName { get; set; }
public string ReturnType { get; set; }
public object ComputeFieldValue(IIndexable indexable)
{
Assert.ArgumentNotNull(indexable, "indexable");
string url = null;
try
{
Item item = indexable as SitecoreIndexableItem;
// This field only works for items uder /sitecore/content that have a layout
if (item == null
|| item.Visualization.Layout == null
|| !item.Paths.FullPath.StartsWith(
Sitecore.Constants.ContentPath,
System.StringComparison.InvariantCultureIgnoreCase))
{
return null;
}
ImageField img = item.Fields["Icon"];
return img == null || img.MediaItem == null ? null : MediaManager.GetMediaUrl(img.MediaItem);
}
catch (WebException webExc)
{
Log.Warn(string.Format("Failed to html index {0} ({1}): {2}", indexable.Id, url, webExc.Message), webExc, this);
}
catch (Exception exc)
{
Log.Error(string.Format("An error occurred when indexing {0}: {1}", indexable.Id, exc.Message), exc, this);
}
return null;
}
}