Build a custom content provider for Sitecore Cortex Content Tagging

Version:

The content provider for Sitecore CortexTM 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.

This topic describes how to:

Implement a custom content provider

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:

    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 illustrated in the following example:

<contentTagging>
    <providers>
        <content>
            <add name="ExampleContentProvider"
type="Custom.ContentTagging.Core.Providers.ExampleContentProvider,
Custom.ContentTagging.Core" />
        </content>
    </providers>
</contentTagging>
If you have suggestions for improving this article, let us know!