image

Exclude/Disable specific items from index in Episerver Find

image By - Ravindra Rathore
15 Dec 2019

Hi Guys,

As you all know that Episerver Find is a preferred indexing tool for Episerver solution and we all use this in our search implementation.

Sometimes we want some pages will not index in our search indexes. Like – Search Landing page itself.

So today I am going to tell you the approach in which you can exclude/disable the indexes for a specific item that you don’t want to store in your Find indexes.

FYI- Alloy solution already provides a CMS field for the “DisableIndexing” but the implementation is missing yet.

Ok so to start with this we just need to add a checkbox in CMS so that content author or admin can exclude any page from the index.

Please add the following field on “BasePage” so that it is available on all the pages and author/admin can disable the indexing.

                                            
[Display(
GroupName = Global.GroupNames.MetaData,
Order = 100)]
[CultureSpecific]
public virtual bool DisableIndexing { get; set; }
                                                

Once this is done you can see this new field in the CMS.

Now you have to create an initialization module so that we can use this field and exclude the items from indexes.


using DisableSpecificItemIndexFind.Models.Pages;
using EPiServer.Find.Cms;
using EPiServer.Find.Cms.Conventions;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
namespace DisableSpecificItemIndexFind.Business.Initialization
{
    [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Find.Cms.Module.IndexingModule))]
    public class DisableItemIndexFindInitialization : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            ContentIndexer.Instance.Conventions.ForInstancesOf().ShouldIndex(x => !x.DisableIndexing);
        }
        public void Uninitialize(InitializationEngine context)
        {
            //Add uninitialization logic
        }
    }
}

This is all from a coding point of view. Now you can use this new feature on your website. Build the solution and login to your site.

Navigate to Find management tool( http://localhost:63205/EPiServer/Find/#overview/explore ) on your website and query for the page that you want to exclude. Like – searchpage.

Let’s navigate to the Search page in the content tree and checked the “Disable indexing” checkbox.

Finally, go to the admin menu and rebuild the Find indexes again using the built-in schedule job(EPiServer Find Content Indexing Job).

Again go to Find console and search for “seachpage” again.

Hurray!! the page is no more in the index.

Thanks for reading this blog post I hope it helps

Thanks and regards

Ravindra S. Rathore