Build a custom taxonomy provider for Sitecore Content Tagging

Abstract

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

The taxonomy provider for Sitecore Content Tagging is responsible for managing tags, and can create and store tags based on TagData objects. The taxonomy provider returns Tag objects based on tag ID, and can also return the parent and/or children of a tag if you have implemented structured taxonomy in the provider. 

This topic describes how to:

To create your own taxonomy provider:

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

    public class ExampleTaxonomyProvider : ITaxonomyProvider
    { 
        public string ProviderId => "ExampleTaxonomyProvider";
    
        public IEnumerable<Tag> CreateTags(IEnumerable<TagData> tagData)
        {
            var tags = new List<Tag>();
            // CREATE AND STORE HERE
            Tag tag = null;
            tags.Add(tag);
            return tags;
        }
    
        public Tag GetTag(string tagId)
        {
            // receive tag from repository based on tagId here
            Tag tag = null;
            return tag;
        }
    
        public Tag GetParent(string tagId)
        {
            // implement if needed
            return null;
        }
    
        public IEnumerable<Tag> GetChildren(string tagId)
        {
            // implement if needed
        return null;
        }
    }
    

To use your provider in a content tagging configuration:

  • Register it in the configuration file, as in the following example:

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