About the coveoBeforeUpdatingIndexFields Pipeline

This pipeline uses the CoveoBeforeUpdatingIndexFields class and can be used to modify the Sitecore field configuration before the fields are created or updated in your Coveo organization.

This pipeline is applied after all Sitecore fields are merged together. This means that all template fields and computed fields are present. Also, the Coveo field names are already resolved for all the fields.

The difference between the actual Sitecore fields and the existing Coveo fields is applied later.

In the processor arguments, you can find the following properties:

Name Type Description

Fields

IList<FieldConfig>

Gets the list of Sitecore fields to process. Fields can be added, modified, and removed from the list.

IndexName

string

Gets the name of the search index to target.

FieldConfig Class Properties

Name Type Description

CoveoFieldName

string

Gets or sets the Coveo field name.

DateFormat

string

Gets or sets the date format for the field.

DefaultValue

string

Gets or sets the field default value for the items in the corresponding Coveo organization source.

Description

string

Gets or sets the field description.

FieldType

FieldType

Gets or sets the field type.

IncludeForFieldQueries

bool

Gets or sets whether the field supports field queries.

IncludeForFreeTextSearch

bool

Gets or sets whether the field supports free text queries.

IsFacet

bool

Gets or sets whether the field can be used as a facet.

IsMultiValue

bool

Gets or sets whether the field can be used as a multi-value facet.

IsSortable

bool

Gets or sets whether the field can be used to sort search results.

SitecoreFieldName

string

Gets or sets the Sitecore field name used as the field metadata in the Coveo field.

Configuration

In the Coveo.SearchProvider.Custom.config, you can add your processor using the arguments under the coveoBeforeUpdatingIndexFields element, which has to be created under pipelines.

Example Usage of the Pipeline

You can use this pipeline to programmatically set if a field can be used as a facet, for sorting, and so on.

Important

It’s also possible to add, remove, or perform more modifications on fields, such as changing the field name or the field type. Note that such changes are potentially dangerous and must be handled with care.

Note

To be able to run the code sample below, your Visual Studio project must reference these assemblies:

  • Coveo.AdbstractLayer.dll

  • Coveo.Framework.dll

using System.Collections.Generic;
using Coveo.AbstractLayer.Pipeline;
using Coveo.Framework.Fields.Config;
using Coveo.Framework.Processor;

namespace Tutorials.Lib.Processors.CoveoBeforeUpdateFieldSetPipeline
{
    /// <summary>
    /// Processor that will set any field with "product" in its name as facet for the "web" database.
    /// </summary>
    public class SetProductFieldsAsFacetForWebDatabase : IProcessor<CoveoBeforeUpdateFieldSetPipelineArgs>
    {
        /// <summary>
        /// The "Process" method is called by the pipeline runner when the pipeline is invoked.
        /// </summary>
        /// <param name="p_Args">The arguments that are passed from processor to processor through the pipeline.</param>
        public void Process(CoveoBeforeUpdateFieldSetPipelineArgs p_Args)
        {
            // Since you know the search index name, you can
            // easily apply your changes only to the Coveo fields associated
            // with the "web" index.
            if (p_Args.IndexName == "Coveo_web_index") {
                SetProductFieldsAsFacet(p_Args.Fields);
            }
        }
        /// <summary>
        /// This method scans the fields and raises the "IsFacet" flag when a field contains "product" in its name.
        /// </summary>
        /// <param name="p_Fields">The list of fields used to build the coveo_web_index.</param>
        private void SetProductFieldsAsFacet(IEnumerable<FieldConfig> p_Fields)
        {
            foreach (FieldConfig field in p_Fields) {
                if (field.SitecoreFieldName.ToLower().Contains("product")) {
                    field.IsFacet = true;
                }
            }
        }
    }
}