The Sitecore.Commerce.Plugin.Search.AbstractAsyncIndexFieldHandler class

Version: 10.3

The Sitecore.Commerce.Plugin.Search.AbstractAsyncIndexFieldHandler class defines a search field handler that implements an asynchronous compose value method (ComposeValueAsync method) that can call a pipeline. You can use this base field handler class in your custom field handler for exceptional cases when you have a requirement to index a real time field value.

The Commerce Engine does not use this index field handler by default. Default index field handler provided out of the box are based on the Sitecore.Commerce.Plugin.Search.AbstractIndexFieldHandler class.

Important

Index field handlers that call pipelines asynchronously can have a negative impact on indexing performance, particularly in deployments with large catalogs or mapping tables. We recommend that you use the AbstractIndexFieldHandler class for your custom field handler whenever possible.

The following is an example of the Sitecore.Commerce.Plugin.Search.AbstractAsyncIndexFieldHandler:

RequestResponse
using System.Collections.Concurrent;
using System.Threading.Tasks;
namespace Sitecore.Commerce.Plugin.Search
{
    /// <summary>
    /// Defines the abstract asynchronous index field handler.
    /// </summary>
    public abstract class AbstractAsyncIndexFieldHandler
    {
        /// <summary>
        /// Composes the field value to be used in the index
        /// </summary>
        /// <param name="source">The source for the value</param>
        /// <param name="context">The context</param>
        /// <returns>The value of the field to be use in the index</returns>
        public abstract Task<objectComposeValueAsync(object sourceConcurrentDictionary<stringobjectcontext);
    }
}
Note

The Sitecore.Commerce.Engine.SDK includes a sample ParentCategoryDisplayNameHandler field handler, which demonstrates how to call a pipeline using the ComposeValueAsync method. The sample handler class is available in the Customer.SampleSolution file, in the scr/Plugin.Sample.Habitat/Search folder.

In the Sitecore.Commerce.Plugin.Search.AbstractAsyncIndexFieldHandler class:

  • The source argument in the ComposeValue provides access to the entity that is being processed.

  • The context dictionary provides further information about the hierarchical location of the entity, the language, the catalog that it belongs to, the current language and more. The following table shows keys and values description.

    Key

    Value

    CommerceContext

    The commerce context to provide information about the current environment.

    SitecoreItemSearchScopePolicy

    The search scope policy provides information about the target index.

    LanguageCode

    The language code.

    Parent

    The ID of the immediate parent entity.

    MappedCatalog

    Provides high-level information about the catalog that this entity belongs to.

    EntityHierarchy

    Hierarchical information about the item. Provides access to the entire path to the given item.

    IndexingOptions

    Information about the current indexing operation. Provides access to the target database name.

    DeterministicId

    The unique ID for the entity that is also used as the Sitecore Item ID in the data provider.

Do you have some feedback for us?

If you have suggestions for improving this article,