Use Out-of-the-Box Computed Fields
Use 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 |
This article explains how to use the three Coveo for Sitecore computed field implementations. These computed fields share a common logic in that they let you retrieve a value stored in a referenced item field.
The ReferencedFieldComputedField
computed field is a generic implementation that lets you pick a field from the referenced item, whereas the refenced item field is hard-coded in ImageUrlComputedField
and ImageAltComputedField
.
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. |
The ReferencedFieldComputedField
Computed Field
This computed field retrieves a specific field from an item referenced by a field.
For example, you could have an item that has a MediaItem
field of type Droptree
, which refers to a File
item containing a Mime Type
field of type text
.
You can also see the Create a Computed Field for a Referenced Item article for a concrete example implementation of this computed field.
To create a new field named mimetype
on the original item and which contains the MIME type of the file, add the following element in your configuration and rebuild your search indexes:
<field fieldName="mimetype" sourceField="MediaItem" referencedFieldName="Mime Type">Coveo.SearchProvider.ComputedFields.ReferencedFieldComputedField, Coveo.SearchProviderBase</field>
Here are the properties and what they refer to:
-
fieldName
: The resulting name of the field in the Coveo index. -
sourceField
: The name of the field in your indexable item that have a value to be replaced. -
referencedFieldName
: The name of the field on the referenced item that contains the value to be used.
Note
The value returned by the computed field is automatically converted to string by default.
You can change this behavior by setting the |
Don’t use special characters in computed field names. |
The ImageUrlComputedField
Computed Field
This computed field retrieves the URL of an image referenced by a field of type Image.
For example, you could have an item that has a field named screenshot
of type Image, and that references an image in the Media Library.
To create a new field containing the URL of the image, add the following element in your configuration and rebuild your search indexes:
<field fieldName="screenshoturl" sourceField="screenshot">Coveo.SearchProvider.ComputedFields.ImageUrlComputedField, Coveo.SearchProviderBase</field>
Don’t use special characters in computed field names. |
Leading practice
Use the retrieved URL to add the Media Library image in a result template. |
The ImageAltComputedField
Computed Field
This computed field retrieves the alternate text (ALT) of an image referenced by a field of type Image.
Given the same scenario as ImageUrlComputedField
, add the following element in your configuration and rebuild your search indexes to create a new field containing the alternate text of the image:
<field fieldName="screenshotalturl" sourceField="screenshot">Coveo.SearchProvider.ComputedFields.ImageAltComputedField, Coveo.SearchProviderBase</field>
Don’t use special characters in computed field names. |