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.

Covid 19
COVID-19: Digital Insights For Enterprise Action

Access Perficient’s latest insights into how you can leverage digital technologies to not only respond to the pandemic, but drive your operations forward and deliver experiences your customers need.

Get Informed

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

About the Author

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

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

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

Subscribe to the Weekly Blog Digest:

Sign Up