Create a Custom coveoInboundFilterPipeline Processor

Coveo inbound filters work exactly like Sitecore inbound filters but are adapted for a Coveo for Sitecore installation. They’re applied only to the Coveo indexes and you can even choose to which indexes you want to apply them.

Important

Note that if excluded items were previously indexed, you must rebuild the index to delete them. Filters don’t delete items from the index, they only filter them out as they’re indexed.

Creating a coveoInboundFilterPipeline Processor

Coveo inbound filters must:

  • Inherit the AbstractCoveoInboundFilterProcessor class.

  • Take arguments of type CoveoInboundFilterPipelineArgs.

  • Invoke the ShouldExecute method to validate if the processor needs to be run.

The following example shows you how to code your own Coveo inbound filter processor, to be called for each item only indexed in the Coveo indexes. This processor is used to exclude the items named __Standard Values.

  1. Create a new C# project that references the Sitecore.ContentSearch.dll, the Sitecore.Kernel, the Coveo.Framework.dll, and the Coveo.SearchProviderBase.dll assemblies. Those assemblies are located under: <SITECORE_INSTANCE_ROOT>\website\bin. For this tutorial, the project is named InboundFilterTest.

  2. Create a new class. For this tutorial, the class is called ApplyCoveoInboundIndexStandardValuesFilter and is located in the InboundFilterTest namespace.

  3. Use the code below for the ApplyCoveoInboundIndexStandardValuesFilter class.

    using Coveo.SearchProvider.Pipelines;
    using Coveo.SearchProvider.InboundFilters;
    
    namespace InboundFilterTest
    {
        public class ApplyCoveoInboundIndexStandardValuesFilter : AbstractCoveoInboundFilterProcessor
        {
            public override void Process(CoveoInboundFilterPipelineArgs args)
            {
                if (args.IndexableToIndex != null && !args.IsExcluded && ShouldExecute(args)) {
                    if (args.IndexableToIndex.Item.Name == "__Standard Values") {
                        args.IsExcluded = true;
                    }
                }
            }
        }
    }

Adding the coveoInboundFilterPipeline Processor to the Pipeline

  1. Open the Coveo.SearchProvider.Custom.config file.

  2. Locate the coveoInboundFilterPipeline node.

  3. Add your processor as a child node:

     <coveoInboundFilterPipeline>
       <processor type="InboundFilterTest.ApplyCoveoInboundIndexStandardValuesFilter, InboundFilterTest" />
     </coveoInboundFilterPipeline>
  4. Validate that the standard values items are excluded from the indexing operations.

Restricting the Processor to a Specific Index

It’s possible to define two lists in the configuration of Coveo Inbound filters:

  • Included indexes: the list of indexes the processor is applied to.

  • Excluded indexes: the list of indexes the processor isn’t applied to.

Note

Exclusion has priority over inclusion. This means that if the same index is specified both in inclusion and exclusion, the processor isn’t applied in the index.

To define which indexes are filtered, specify the following indexes in your processor definition:

<coveoInboundFilterPipeline>
  <processor type="InboundFilterTest.ApplyCoveoInboundIndexStandardValuesFilter, InboundFilterTest">
    <!-- Includes the Coveo_web_index to the list of filtered indexes. -->
    <includedIndexNames hint="list">
      <indexName>Coveo_web_index</indexName>
    </includedIndexNames>
    <!-- Excludes the Coveo_master_index to the list of filtered indexes. -->
    <excludedIndexNames hint="list">
      <indexName>Coveo_master_index</indexName>
    </excludedIndexNames>
  </processor>
</coveoInboundFilterPipeline>