Build a custom discovery provider for Sitecore Content Tagging

Version: 10.4

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:

Implement a custom discovery provider

To create your own discovery provider:

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

    RequestResponse
    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;
        }
    }
    

Add the discovery provider to the configuration file

To use your provider in the content tagging configuration:

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

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

Do you have some feedback for us?

If you have suggestions for improving this article,