Gravatar for

Question by jkramer, Dec 1, 2015 4:20 AM

Computed fields not getting computed - external config


I am trying to migrate a number of Lucene indices to Coveo. However, I ran into an issue early on. The information about the indices is being pieced together from a number of config files. One such index, itself in a separate config, references another config file which among others contains the declaration of the computed fields in a custom configuration tag. After changing the index definition as per the instructions located here, I then change the ref attribute (Step 5) to point to the custom configuration instead of the default one. The problem is now that the computed fields aren't being indexed, even if I change the configuration type attribute to Coveo.SearchProvider.Configuration.CoveoSearchConfiguration, Coveo.SearchProvider. Is it even possible to proceed like this? Or is the process described in here the only way of adding computed fields to Coveo? Thanks in advance for your reply.


Coveo for Sitecore version information

Current Coveo for Sitecore version: 3.0.1123.0

Current Sitecore version: 7.0.130918

1 Reply
Gravatar for

Answer by Luc Bergeron, Dec 2, 2015 4:26 PM


You can patch computed fields using a separate configuration file. The thing is that you cannot patch them per index, but patching the defaultIndexConfiguration element works. For example, I can patch in a computed field using this include file.

<configuration xmlns:patch="">
      <configuration type="Coveo.SearchProvider.Configuration.CoveoSearchConfiguration, Coveo.SearchProvider">
        <defaultIndexConfiguration type="Coveo.Framework.Configuration.CoveoIndexConfiguration, Coveo.Framework">
          <fields hint="raw:AddComputedIndexField">
            <field fieldName="customAllTemplates">Sitecore.ContentSearch.ComputedFields.AllTemplates, Sitecore.ContentSearch</field>

I hope this helps

Gravatar for

Comment by jkramer, Dec 3, 2015 4:38 AM

Hello lbergeron,

thanks for your answer, one more question though: is there a hassle-free way of conditionally setting computed fields according to template to avoid index bloat?

Gravatar for

Comment by Luc Bergeron, Dec 3, 2015 9:32 AM


You can avoid bloating the index with unnecessary fields by returning the null value. Basically, your computed field should check whether the indexed item matches a given template. If the template is different, then the computed field returns null, otherwise it computes the field value and return it.

If you have many computed fields with this behavior, then you might want to extract this part in a base class or a utility method. Here is some basic code showing how to implement the ComputeFieldValue method.

public object ComputeFieldValue(IIndexable p_Indexable)
    SitecoreIndexableItem indexableItem = p_Indexable as SitecoreIndexableItem;
    if (indexableItem == null || indexableItem.Item == null || indexableItem.Item.TemplateID != SOME_TEMPLATE_ID) {
        return null;

    // computed field logic goes here
Gravatar for

Comment by jkramer, Dec 4, 2015 3:41 AM

Thanks again lbergeron.

Ask a question