Using Out of the Box Computed Fields
Using Out of the Box Computed Fields
In addition to the computed fields already used by default in the Coveo Search Provider configuration file, Coveo also provides a few ones that you can use optionally.
Coveo.SearchProvider.ComputedFields.ImageUrlComputedField
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 refers to 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>
Coveo.SearchProvider.ComputedFields.ImageAltComputedField
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>
Coveo.SearchProvider.ComputedFields.ReferencedFieldComputedField
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
.
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.
The value returned by the computed field is automatically converted to string by default. You can change this behavior by setting the returnType
attribute to one of the supported Sitecore data types: Integer, Number, date, datetime, or string.