Computed fields

Sometimes, recording information in a Sitecore template field isn’t practical, time-consuming, or error prone. If you need to store complementary information in your Coveo index items and this information can be determined using the same recipe from one item to the next, consider using a computed field instead.

Sitecore gives you the ability to create computed fields programmatically at indexing time using custom C# code and field configurations. Coveo for Sitecore simplifies the process of adding computed fields to your Coveo indexes by doing part of this work.

Note

In the Fields page of the Command Center, the Computed tab displays all computed fields you add or create, along with Sitecore’s own computed fields.

Image showing sample content of Computed fields in the Command Center | Coveo for Sitecore 5

Coveo for Sitecore supports two main computed field implementation scenarios:

Using Coveo for Sitecore out-of-the-box computed fields

Coveo for Sitecore includes out-of-the-box implementations that let you add computed fields for common use cases without any coding on your part. Coveo for Sitecore also provides commented out field indexing configurations for these computed fields in the Coveo.SearchProvider.Custom.config file, in the <fields hint="raw:AddComputedIndexField"> section. You only need to provide a few attribute values and enable the configuration to have your computed fields added on indexing.

Note

This configuration lets you create and index the computed field. If you want to apply special settings to that field (for example, to use it as a facet or to sort results), you also need to add a configuration in the fieldNames section of the configuration file.

  • Use out-of-the-box computed fields

    This article explains how to use the three Coveo for Sitecore computed field implementations (that is, ImageUrlComputedField, ImageAltComputedField, and ReferencedFieldComputedField).

  • Create a computed field for a referenced item

    This article provides an example showing how to use the out-of-the-box ReferencedFieldComputedField computed field. ReferencedFieldComputedField is used to populate a departureairportcity field in Flight items by retrieving the content of a City field from a referenced Airport item.

Implementing a computed field of your own

In this scenario, you’ll need to code the logic of your computed field. Coveo for Sitecore provides a computed field configuration element structure. Minimal configuration is required to have your computed field added on indexing.

Warning

When running computed field code, check your logs for computed field errors indicating items aren’t being indexed. Implement proper exception handling to avoid these issues. For example, you might want to stop the process or set a fallback value for a computed field when suitable.