Skip to main content

Back-End Development

Coveo for Sitecore: Customizing Index Parameters

Search@1x.jpg

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

Thoughts on “Coveo for Sitecore: Customizing Index Parameters”

  1. Zoran Babovic Post author

    > 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Zoran Babovic

Zoran has over 8 years of experience in web application development and is skilled in many programming technologies including C#, MVC.NET, JavaScript, ASP.NET and jQuery. He is a certified Sitecore developer as well as certified Coveo for Sitecore V4 developer. Zoran has used his expertise to deliver custom Sitecore and Coveo solutions for several enterprise clients. In his free time his hobbies are playing bass guitar and throwing darts. Zoran's focus is on creating high quality web applications.

More from this Author

Follow Us