Build a custom discovery provider for Sitecore Content Tagging

Abstract

How to create a custom discovery provider for content tagging and how to add it to your environment.

The discovery provider for Sitecore Content Tagging returns tags based on content from the content provider.

The discovery provider takes a collection of TaggableContent objects as input and returns a collection of TagData objects as output.

This topic describes how to:

To create your own discovery provider:

  • Implement the Sitecore.ContentTagging.Core.Providers.IDiscoveryProvider¬†interface as illustrated in the following example:

    public class ExampleDiscoveryProvider : IDiscoveryProvider
    {
        public IEnumerable<TagData> ProcessContent(IEnumerable<TaggableContent> content)
        {
            var tags = new List<TagData>();
            foreach (var taggableContent in content)
            {
                // cast taggableContent object to concrete type returned by ContentProvider
                // TaggableContent is an abstract class and has no properties
                var stringContent = (StringContent)taggableContent;
                // YOUR PROVIDER LOGIC HERE
                // with provided content (stringContent) your provider should return a response
                // from which you can create TagData objects
                // convert response provided by your provider logic into TagData objects
                TagData item = new TagData
                {
                    //TagName = "TAG_NAME"
                    //Relevance = 5
                };
                tags.Add(item);
            }
            return tags;
        }
    }
    

To use your provider in the content tagging configuration:

  • Register the custom discovery provider in the configuration file, as in the following example:

    <contentTagging>
        <providers>
            <discovery>
                <add name="ExampleDiscoveryProvider"
    type="Custom.ContentTagging.Core.Providers.ExampleDiscoveryProvider,
    Custom.ContentTagging.Core" />
            </discovery>
        </providers>
    </contentTagging>