Try our conversational search powered by Generative AI!

How to use IContentIndexerConventions.ShouldIndexInContentAreaConvention to index content of ContentAreaItem



I have a requirement to allow content of ContentAreaItem item to be indexed with page content in SearchText and of course, I can’t use [IndexInContentarea] attribute due to some restrictions on referencing.

So, is it possible to do that with the help of IContentIndexerConventions.ShouldIndexInContentAreaConvention

If it is, then how? I tried to find a code sample, but total waste of time. Can anyone help me with how to use this (ShouldIndexInContentAreaConvention) to allow a Block (say CopyBlock) to get it's content indexed.

Mar 06, 2019 12:01

Hi Praful,

First create your IShouldIndexInContentAreaConvention implementation:

public class ShouldIndexCopyBlockInContentAreaConvention : IShouldIndexInContentAreaConvention
    public bool? ShouldIndexInContentArea(IContent contentInArea)
        // Add whatever additional logic you need here!

        if (contentInArea is CopyBlock)
            return true;

        return false;

Then go ahead and replace the default via an InitializableModule:

public class SearchConventionInitializationModule : IInitializableModule
    public void Initialize(InitializationEngine context)
        ContentIndexer.Instance.Conventions.ShouldIndexInContentAreaConvention = new ShouldIndexCopyBlockInContentAreaConvention();

    public void Uninitialize(InitializationEngine context) {}

This example is obviously ridiculously simple, you could also take a peek at the DefaultShouldIndexInContentAreaConvention (in EPiServer.Find.Cms.Conventions) where the published status of the content is checked before indexing (it's probably worth doing something similar).

Anyway, hope that gives you a starting point.


Mar 06, 2019 17:05

Hi Jake,

First of all thank you so much, this example worked. Really helpful information. :)

Mar 07, 2019 4:25
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.