Kentico: Creating your own Indexing API Indexer

In this article you’ll find:

Goal

The purpose of this article is to show you how to create your own Indexer and how to use it instead of the default one.

Overview

In order to define your custom Hawksearch Indexer which will be used instead of the default one, there are 2 approaches - create your own indexer class which implements the IHawksearchIndexer interface or inherit from the existing Indexer class and override your desired functionality. You also need to register the new indexer class within Kentico’s CMS.Core.Service container.

Steps to creating your own indexer

  1. Create a new module to contain the initialization code: https://docs.xperience.io/custom-development/creating-custom-modules/initializing-modules-to-run-custom-code . For the sake of simplicity, you can create the following files directly inside the CMSApp project that references Hawksearch.Kentico.Xperience.CMS NuGet package. Realistically, you would most likely want to create your own project which will reference Hawksearch.Kentico.Xperience.CMS and then have the CMSApp project reference your newly created project.

  2. Either create your own class which implements Hawksearch.Kentico.Xperience.CMS.Services.Indexing.Contracts.IHawksearchIndexer or inherit from Hawksearch.Kentico.Xperience.CMS.Services.Indexing.Indexer.

  3. Implement your custom logic.

  4. In the module’s OnPreInit method, register your new indexer class. Here CustomIndexer is assumed to be your indexer class, so replace it with your own class name:

    protected override void OnPreInit() { base.OnPreInit(); CMS.Core.Service.Use<IHawksearchIndexer,CustomIndexer>(); }

5. Now the system will use your custom indexer.