Is there a way to re-use the code for a computed index field without just making derived classes? I would like to have an additional property in the config which tells the ComputeFieldValue method which template field to read from.
So my config patch would look like this:
<field
fieldName="mounting"
templateFieldName="Mounting" <<new property here
returnType="stringCollection">
MyNamespace.MyComputedIndexField, MyAssembly
</field>
And my indexing class would be as follows:
public class MyComputedIndexField : AbstractComputedIndexField
{
public string TemplateFieldName { get; set; }
public override object ComputeFieldValue(IIndexable indexable)
{
Item item = indexable as SitecoreIndexableItem;
if (item == null)
{
return null;
}
var values = item[TemplateFieldName]?.Split(new[] {";"}, StringSplitOptions.RemoveEmptyEntries); //readthe TemplateFieldName property here
return values?.Select(v => v.Trim()).ToList();
}
}
Obviously, I could just set the default fieldName property to the name of the template field, but that would constrain my field name to be named after the template field name.