Understanding the coveoBeforeUpdatingIndexFields Pipeline
Understanding the coveoBeforeUpdatingIndexFields Pipeline
This pipeline uses the CoveoBeforeUpdatingIndexFields
class and can be used to modify the Sitecore field configuration before the field set is created or updated in CES.
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 field set in CES is applied later.
In the processor arguments, you can find the following properties:
Name | Type | Description |
---|---|---|
Fields | IList<FieldConfig> | Gets the list of fields that are to be included in the field set. Fields can be added, modified, and removed from the list. |
IndexName | string | Gets the name of the search index for which the field set is being created. |
FieldConfig Class Properties
Name | Type | Description |
---|---|---|
CoveoFieldName | string | Gets or sets the field name in the field set. |
DateFormat | string | Gets or sets the date format for the field. |
DefaultValue | string | Gets or sets the field default value. This value will appear on every item of a source that uses this field set when no other value is specified. |
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 field set. |
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.
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.
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 field set that
// matches 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 field set in CES.</param>
private void SetProductFieldsAsFacet(IEnumerable<FieldConfig> p_Fields)
{
foreach (FieldConfig field in p_Fields) {
if (field.SitecoreFieldName.ToLower().Contains("product")) {
field.IsFacet = true;
}
}
}
}
}