THIS IS ARCHIVED DOCUMENTATION

Adding a Field to a Result Template Using the Coveo for Sitecore Legacy Search UI Framework

Coveo for Sitecore (November 2018)

You can choose exactly which fields you display in the search result layout so the information is always the most relevant possible to your users. This page covers how someone with some developer skills can modify the search layout template to display additional fields.

Step 1: Choose the Fields That You Want to Display

There are three kinds of fields that can be displayed:

Sitecore fields These are the fields present on your Sitecore items. In the Coveo index, they're indexed using a special naming convention: @f followed by the name of the Sitecore field. This convention applies to computed fields as well.
System fields These fields are automatically added by the Coveo index. They start with the @sys prefix.
Custom fields

These fields can be created and indexed on demand by the Coveo index. They start with the @ prefix only, but they don't necessarily follow any specific naming convention.

You must add these custom fields in the fieldMap node of the Coveo.SearchProvider.Custom.config (see Understanding the Coveo Search Provider’s Configuration File)

For example, an item based on the Flight template has the Price field, which could be indexed as @fprice67819 in the Coveo index.

The number suffix in Sitecore field names (for example, 67819) comes from a hash value constructed from the name of the Sitecore source in your Coveo index. This is to avoid field name collisions.

Step 2: Include the New Field in the Coveo Search Component

  1. Using a text editor, edit the user control associated with the Coveo Search component (for example, CustomCoveoSearch.ascx).
  2. Scroll to the first table element that has a class attribute equal to CoveoFieldTable.
  3. Insert either one of these elements depending on the type of field that you have chosen:
    1. For a Sitecore field name:

      Coveo for Sitecore (October 2016) The recommended option is to use the Coveo Fields Resources:

       <tr data-field='coveoFieldName("@SitecoreFieldName")' data-caption='My Sitecore Field' />
      

      So for the Price field for example, you would use:

       <tr data-field='coveoFieldName("@Price")' data-caption='Price' />
      

      The coveoFieldName helper method translates the Sitecore field name to its raw field name (that is, as it’s stored in the Coveo index) using client-side JavaScript.

      It’s only available when the Coveo Fields Resources component is included in the same page.

      For versions prior to the October 2016 release

      Use the Utility method:

       <tr data-field='<%= ToCoveoFieldName("SitecoreFieldName") %>' data-caption='My Sitecore Field' />
      

      So for the Price field for example, you would use:

       <tr data-field='<%= ToCoveoFieldName("Price") %>' data-caption='Price' />
      

      The ToCoveoFieldName utility method translates the Sitecore field name to its raw field name, that is, as it’s stored in the Coveo index using server-side ASP.Net.

    2. For a Coveo system or custom field:

       <tr data-field='@coveofieldname' data-caption='My Coveo Field' />
      

      So for the sysauthor field for example, you would use:

       <tr data-field='@sysauthor' data-caption='Author' />
      
  4. Save the file.
  5. Validate that your new field appears in the search interface.