Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

In order to create a new handler, you need to create a class and inherit from IndexingHandlerBase abstract class. Then, you will have to override 2 methods:

public abstract string Name { get; }
public abstract void Execute(IIndexingContext context);

The first one is a property representing the name of the handler.

The second one is a method that represents the inner workings of the handler.

To include the handler in the indexing process, you have to add it to the indexing chain using the

AddHandler<TType>() where TType : IIndexingHandler method, part of the IndexingChain class.

Choose a position in either the Full Indexing or Incremental Indexing chains, and call the method with the generic type TType equal to the one of the handler you created. The position will determine the moment in the indexing chain where the handler will run its Execute method’s code.

Example of how to add a custom handler:

public class CustomHandler : IndexingHandlerBase
{
    public override string Name => "Custom Handler";
    
    public override void Execute(IIndexingContext context)
    {
        //Your code here
    }
}
private IndexingChain FullIndexingChain(IContainer container)
{
    return new IndexingChain(container)
        .AddHandler<DeletePreviousIndexHandler>()
        .AddHandler<CreateIndexHandler>()
        .AddHandler<CustomHandler>() // add your handler here 
        .AddHandler<RebuildIndexHandler>()
        .AddHandler<SetCurrentIndexHandler>();
}

In the example, CreateIndexHandler will run before CustomHandler and RebuildIndexHandler immediately after.

  • No labels