Build a custom content provider for Sitecore Cortex Content Tagging

Current version: 9.3

By default, the Sitecore CortexTM Content Tagging feature can process any content item in Sitecore. When it processes an item for tagging with the default configuration, it only includes the content of Multi-Line Text fields, Rich Text fields, and fields with the name Title. However, you can determine which fields are included in the tagging process. You can do this by changing the configuration file, or by using a custom content provider.

This topic describes how to:

Implement a custom content provider

The content provider for Sitecore Cortex Content Tagging returns content ready for analysis based on the object that the user selected for tagging.

As input, the content provider takes objects of type T, where T is a generic type.  For use with Sitecore, you will probably use the Item type for T.

As output, the content provider returns a TaggableContent object.

To create your own content provider:

  1. Implement the generic Sitecore.ContentTagging.Core.Providers.IContentProvider interface. 

  2. Specify the generic TSource parameter, which is an input parameter for a method that you must implement. In the default scenario, the input will be an item.

  3. Implement the content provider as illustrated in the following example:

    RequestResponse
    public class ExampleContentProvider: IContentProvider<Item>
    {
        public TaggableContent GetContent(Item source)
        {
            // TaggableContent is an abstract class and has no properties
            // that's why we use StringContent here
            var stringContent = new StringContent();
            // fetch content from your source object here
            stringContent.Content = source.Fields["Content"].Value;
            return stringContent;
        }
    }

Add the content provider to the configuration file

Add the content provider to the configuration file, as in the following example:

RequestResponse
<contentTagging>
    <providers>
        <content>
            <add name="ExampleContentProvider"
type="Custom.ContentTagging.Core.Providers.ExampleContentProvider,
Custom.ContentTagging.Core" />
        </content>
    </providers>
</contentTagging>

Enable a custom content provider

To enable a custom content provider:

  1. Implement the custom configuration pipeline processor, as in the following example:

    RequestResponse
    public class GetCustomConfigurationName
    {
        public void Process(GetTaggingConfigurationArgs args)
        {
            //perform check
            if ()
            {
                 args.ConfigurationName "CustomConfiguration";
            }
         }
    ...
  2. In the configuration file, create a new named configuration set and include the new content provider, as in the following example:

    RequestResponse
    <contentTagging>
      <configurations>
        <config name="CustomConfiguration">
          <content>
            <provider name="CustomContentProvider"/>
          </content>
          <tagger>
            <provider name="DefaultTagger"/>
          </tagger>
          <taxonomy>
            <provider name="DefaultTaxonomyProvider"/>
          </taxonomy>
        </config>
      </configurations>
    </contentTagging> 
  3. Add the custom pipeline processor to the getTaggingConfiguration pipeline. With this processor, you can change the active configuration for the specific item type.

    RequestResponse
    <getTaggingConfiguration>
        <processor type="Sitecore.ContentTagging.Pipelines.GetTaggingConfiguration.GetDefaultConfigurationName, Sitecore.ContentTagging" resolve="true" />
        <processor type="Sitecore.ContentTagging.Pipelines.GetTaggingConfiguration.GetCustomConfigurationName, Sitecore.ContentTagging" resolve="true" />
        <processor type="Sitecore.ContentTagging.Pipelines.GetTaggingConfiguration.BuildConfiguration, Sitecore.ContentTagging" resolve="true" />
    </getTaggingConfiguration>

Do you have some feedback for us?

If you have suggestions for improving this article,