The Sitecore.Commerce.Plugin.Search.AbstractAsyncIndexFieldHandler class
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.
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:
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<object> ComposeValueAsync(object source, ConcurrentDictionary<string, object> context);
}
}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
sourceargument in theComposeValueprovides access to the entity that is being processed. -
The
contextdictionary 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
CommerceContextThe commerce context to provide information about the current environment.
SitecoreItemSearchScopePolicyThe search scope policy provides information about the target index.
LanguageCodeThe language code.
ParentThe ID of the immediate parent entity.
MappedCatalogProvides high-level information about the catalog that this entity belongs to.
EntityHierarchyHierarchical information about the item. Provides access to the entire path to the given item.
IndexingOptionsInformation about the current indexing operation. Provides access to the target database name.
DeterministicIdThe unique ID for the entity that is also used as the Sitecore Item ID in the data provider.