Excluding items from Coveo indexing and search
Working with Coveo for Sitecore you’ve probably encountered the need to prevent some items from being indexed or displayed in your search results. The other day a client asked me how they could exclude specific user-related pages (e.g. login, registration, and change password pages) from showing up in search results. In their own words they needed an easy way to mark specific pages and prevent them from being indexed.
Sure, you could exclude certain templates by adding them to the excludeTemplate section in Coveo.SearchProvider.config. However, since these pages share a common template with other pages that should be indexed, adding them to excludeTemplate section isn’t an option. Another option would be to add filtering rules to prevent items from showing in your search results based on certain criteria. However, since this will be part of your advanced query which gets dispatched each time you run a search, adding too many filtering rules may impact performance.
This is where custom field comes into play. In the example below we used No Index field. This field comes with the SCORE accelerator out of the box, as part of Page Meta Data template. However, any Checkbox type field can be used to achieve this functionality.
No Index field offers a more granular approach
In order to use this during indexing, you will need to add a custom processor to your CoveoInboundFilterPipeline. So, the first step is to implement a class which inherits from AbstractCoveoInboundFilterProcessor:
public class NoIndexFilter : AbstractCoveoInboundFilterProcessor     {         public override void Process(CoveoInboundFilterPipelineArgs args)         {             if (args.IndexableToIndex != null && !args.IsExcluded && ShouldExecute(args))             {                 if (args.IndexableToIndex.Item.GetField("No Index") != null && args.IndexableToIndex.Item.GetFieldValue("No Index") == "1")                 {                     args.IsExcluded = true;                 }             }         }     }
Last step, configure the Coveo Search Provider
After that, all that remains is to add this processor to coveoInboundFilterPipeline in SeachProvider.custom.config:
<pipelines>   <coveoInboundFilterPipeline>     <processor type="MyNamespace.Data.Processors.NoIndexFilter, MyNamespace.Data" />   </coveoInboundFilterPipeline> </pipelines>
Using this method can really give you more control and speed up your indexing operations. Until next time.
Happy Coveoing 🙂
Zoran
Nice post Zoran. I would add that Sitecore doesn’t have the “No Index” field out of the box. It has to be added to a base template of all your templates to see it in the Content Editor.
> Thank you for the feedback Jean-François. “No Index” field comes with SCORE out of the box, as part of Page Meta Data template. I will make some modifications to the post to clarify.
> Thanks for the update. Again, really nice article.