Indexing Setup
There are 3 main indexing strategies that the connector supports:
Default. Variant Attributes Roll-up inside their parent product
Index variants separately. Separate documents are created for products and variants
Â
To set up indexing inside your project, you should use the Initialization Modules capability (by implementing the IConfigurableModule
interface) provided by the Optimizely platform and make your module dependent on the BasicHawksearchInitialization
module which is part of the installed connector.
Configure Indexing Services
In the ConfigureContainer
method, register services needed to index different types of content. Available options are:
container.AddHawksearchCategoryIndexing<YOUR CLASS EXTENDING NodeContent>();
container.AddHawksearchProductIndexing<YOUR CLASS EXTENDING ProductContent>();
container.AddHawksearchVariantIndexing<YOUR CLASS EXTENDING VariationContent>();
container.AddHawksearchBundleIndexing<YOUR CLASS EXTENDING BundleContent>();
container.AddHawksearchPackageIndexing<YOUR CLASS EXTENDING PackageContent>();
container.AddHawksearchPageIndexing<YOUR CLASS EXTENDING PageData>()
AddHawksearchPageIndexing
extension method can be used multiple times with different generics in order to have multiple cms page types indexed in Hawksearch.
If you don’t intend to index some of the cms or commerce entity type, there’s no need to register those services (e.g. if you don’t have bundles or packages in your project, you should not call the AddHawksearchBundleIndexing
or the AddHawksearchPackageIndexing
methods).
Â
Initialize Indexing Chains
In the Initialize
method, register the 2 chains of Handlers needed for the Full & Incremental Indexing jobs as follows:
public void Initialize(InitializationEngine context)
{
Container.Service.Configure(config =>
{
config.For<IFullIndexingChain>().Add(() => FullIndexingChain(Container.Service))
.Transient();
config.For<IIncrementalIndexingChain>().Add(() => IncrementalIndexingChain(Container.Service))
.Transient();
});
}
private IndexingChain FullIndexingChain(IContainer container)
{
return new IndexingChain(container)
.AddHandler<DeletePreviousIndexHandler>()
.AddHandler<CreateIndexHandler>()
.AddHandler<CategoriesIndexingHandler<YOUR CLASS EXTENDING NodeContent>>()
.AddHandler<HierarchyRebuildHandler>()
.AddHandler<ProductsIndexingHandler<YOUR CLASS EXTENDING ProductContent>>()
.AddHandler<VariantsIndexingHandler<YOUR CLASS EXTENDING VariationContent>>()
.AddHandler<BundlesIndexingHandler<YOUR CLASS EXTENDING BundleContent>>()
.AddHandler<PackagesIndexingHandler<YOUR CLASS EXTENDING PackageContent>>()
.AddHandler<PagesIndexingHandler<YOUR CLASS EXTENDING PageData>>()
... other PagesIndexingHandler registrations for different types of cms pages
.AddHandler<RebuildIndexHandler>()
.AddHandler<SetCurrentIndexHandler>();
}
private IndexingChain IncrementalIndexingChain(IContainer container)
{
return new IndexingChain(container)
.AddHandler<GetCurrentIndexHandler>()
.AddHandler<CategoriesIncrementalIndexingHandler<YOUR CLASS EXTENDING NodeContent>>()
.AddHandler<CategoriesDeletionHandler>()
.AddHandler<HierarchyRebuildHandler>()
.AddHandler<CategoriesCascadeIndexingHandler>()
.AddHandler<ProductsIncrementalIndexingHandler<YOUR CLASS EXTENDING ProductContent>>()
.AddHandler<VariantsIncrementalIndexingHandler<YOUR CLASS EXTENDING VariationContent>>()
.AddHandler<BundlesIncrementalIndexingHandler<YOUR CLASS EXTENDING BundleContent>>()
.AddHandler<PackagesIncrementalIndexingHandler<YOUR CLASS EXTENDING PackageContent>>()
.AddHandler<PagesIncrementalIndexingHandler<YOUR CLASS EXTENDING PageData>>()
... other PagesIncrementalIndexingHandler registrations for different types of cms pages
.AddHandler<EntriesDeletionHandler>()
.AddHandler<PagesDeletionHandler>()
.AddHandler<RebuildIndexHandler>();
}
If you don’t intend to index some of the cms or commerce entity type, you should not add that particular handlers to your indexing chains (e.g. if you don’t have bundles, you will skip adding the BundlesIndexingHandler
and the BundlesIncrementalIndexingHandler
to the indexing chains).
If you don’t intend to index cms pages, PagesIndexingHandler
,PagesIncrementalIndexingHandler
,PagesDeletionHandler
should not be added to the indexing chains.
Â
[IncludeInHawksearch] Attribute
[IncludeInHawksearch]
is an attribute used to decorate properties which we want to index.
Examples:
[IncludeInHawksearch]
[BackingType(typeof(PropertyString))]
[Display(Name = "Brand", GroupName = SystemTabNames.Content, Order = 15)]
public virtual string Brand { get; set; }
[IncludeInHawksearch]
[Display(Name = "On sale", GroupName = SystemTabNames.Content, Order = 50)]
public virtual bool OnSale { get; set; }
This attribute is common for all 3 indexing strategies. For the Variant Attributes Roll-up Strategy, the properties of the variant decorated with this attribute will be rolled-up inside the parent product.
Out of the box, only properties with the following types can be decorated with [IncludeInHawksearch]
attribute:
.NET specific
Optimizely specific
Â
Other property types will throw a NotSupportedException
.
To support more types, please refer to this.