Indexing is wide and complex process. Usually we get default solution to use default indexes, to save our time and effort. Probably in most common scenarios it is sufficient solution. But what when we have a lot of data and we would like to separate our data from default content data or we would like to separate invoking particular object indexing, scale this process etc.
The best option is to create our own custom index.
This approach is also doable to obtain in xCommerce. What we have to do is to write our own custom patches to switch indexing configuration to ours.
1. Custom Product Index declaration with commerce templates indexing
<?xml version="1.0" encoding="utf-8"?> | |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/"> | |
<sitecore role:require="Standalone or ContentManagement" search:require="solr"> | |
<contentSearch> | |
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch"> | |
<indexes hint="list:AddIndex"> | |
<index id="products_master_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider"> | |
<param desc="name">$(id)</param> | |
<param desc="core">Custom_products_master_index</param> | |
<param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" /> | |
<configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration" /> | |
<strategies hint="list:AddStrategy"> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/syncMaster" /> | |
</strategies> | |
<locations hint="list:AddCrawler"> | |
<crawler type="Custom.Foundation.Indexing.Crawler.ProductsCrawler, Custom.Foundation.Indexing"> | |
<Database>master</Database> | |
<Root>/sitecore</Root> | |
</crawler> | |
</locations> | |
<enableItemLanguageFallback>false</enableItemLanguageFallback> | |
<enableFieldLanguageFallback>false</enableFieldLanguageFallback> | |
</index> | |
<index id="products_web_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider"> | |
<param desc="name">$(id)</param> | |
<param desc="core">Custom_products_web_index</param> | |
<param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" /> | |
<configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration" /> | |
<strategies hint="list:AddStrategy"> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsyncSingleInstance" /> | |
</strategies> | |
<locations hint="list:AddCrawler"> | |
<crawler type="Custom.Foundation.Indexing.Crawler.ProductsCrawler, Custom.Foundation.Indexing"> | |
<Database>web</Database> | |
<Root>/sitecore</Root> | |
</crawler> | |
</locations> | |
<enableItemLanguageFallback>false</enableItemLanguageFallback> | |
<enableFieldLanguageFallback>false</enableFieldLanguageFallback> | |
</index> | |
</indexes> | |
</configuration> | |
</contentSearch> | |
</sitecore> | |
</configuration> |
2. Product Index strategies and crawlers definition for xCommerce
<?xml version="1.0" encoding="utf-8"?> | |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/"> | |
<sitecore role:require="Standalone or ContentManagement" search:require="solr"> | |
<contentSearch> | |
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch"> | |
<indexes role:require="Standalone or ContentManagement"> | |
<index id="products_master_index"> | |
<strategies hint="list:AddStrategy"> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/sellableItemsIntervalAsynchronousStrategyMaster" /> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/categoriesIntervalAsynchronousStrategyMaster" /> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/catalogsIntervalAsynchronousStrategyMaster" /> | |
</strategies> | |
<locations hint="list:AddCrawler"> | |
<crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.AllCatalogItemsCrawler, Sitecore.Commerce.Engine.Connect"> | |
<ItemsToTake>100</ItemsToTake> | |
<Environments hint="list"> | |
<environment>HabitatAuthoring</environment> | |
</Environments> | |
<Database>master</Database> | |
</crawler> | |
</locations> | |
</index> | |
<index id="products_web_index"> | |
<strategies hint="list:AddStrategy"> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/sellableItemsIntervalAsynchronousStrategyWeb" /> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/categoriesIntervalAsynchronousStrategyWeb" /> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/catalogsIntervalAsynchronousStrategyWeb" /> | |
</strategies> | |
<locations hint="list:AddCrawler"> | |
<crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.AllCatalogItemsCrawler, Sitecore.Commerce.Engine.Connect"> | |
<ItemsToTake>100</ItemsToTake> | |
<Environments hint="list"> | |
<environment>HabitatAuthoring</environment> | |
</Environments> | |
<Database>web</Database> | |
</crawler> | |
</locations> | |
</index> | |
</indexes> | |
</configuration> | |
</contentSearch> | |
</sitecore> | |
</configuration> |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/"> | |
<sitecore role:require="Standalone or ContentManagement" search:require="solr"> | |
<contentSearch> | |
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch"> | |
<indexes> | |
<index id="sitecore_master_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider"> | |
<strategies> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/sellableItemsIntervalAsynchronousStrategyMaster"> | |
<patch:delete/> | |
</strategy> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/categoriesIntervalAsynchronousStrategyMaster"> | |
<patch:delete/> | |
</strategy> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/catalogsIntervalAsynchronousStrategyMaster"> | |
<patch:delete/> | |
</strategy> | |
</strategies> | |
<locations> | |
<crawler patch:instead="*[@type='Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch']" type="Custom.Foundation.Indexing.Crawler.CustomSitecoreCrawler, Custom.Foundation.Indexing"> | |
<Database>master</Database> | |
<Root>/sitecore</Root> | |
</crawler> | |
<crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.AllCatalogItemsCrawler, Sitecore.Commerce.Engine.Connect"> | |
<patch:delete/> | |
</crawler> | |
</locations> | |
</index> | |
<index id="sitecore_web_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider"> | |
<strategies> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/sellableItemsIntervalAsynchronousStrategyWeb"> | |
<patch:delete/> | |
</strategy> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/categoriesIntervalAsynchronousStrategyWeb"> | |
<patch:delete/> | |
</strategy> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/catalogsIntervalAsynchronousStrategyWeb"> | |
<patch:delete/> | |
</strategy> | |
</strategies> | |
<locations> | |
<crawler patch:instead="*[@type='Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch']" type="Custom.Foundation.Indexing.Crawler.CustomSitecoreCrawler, Custom.Foundation.Indexing"> | |
<Database>web</Database> | |
<Root>/sitecore</Root> | |
</crawler> | |
<crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.AllCatalogItemsCrawler, Sitecore.Commerce.Engine.Connect"> | |
<patch:delete/> | |
</crawler> | |
</locations> | |
</index> | |
</indexes> | |
</configuration> | |
</contentSearch> | |
</sitecore> | |
</configuration> |
4. We have to indicate for xCommerce new index. To make it we need to prepare new Index Resolver with custom values.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/"> | |
<sitecore role:require="Standalone or ContentDelivery or ContentManagement"> | |
<commerceEngineConnector> | |
<types> | |
<type patch:instead="*[@name='IIndexResolver']" name="IIndexResolver" type="Custom.Foundation.Indexing.IndexResolver.CustomCommerceIndexResolver, Custom.Foundation.Indexing" lifetime="PerCall" /> | |
</types> | |
</commerceEngineConnector> | |
</sitecore> | |
</configuration> |
public class CustomCommerceIndexResolver : IIndexResolver | |
{ | |
private const string IndexNameTemplate = "products_{0}_index"; | |
public string GetIndexName(Database database, string catalogName) | |
{ | |
return string.Format((IFormatProvider)CultureInfo.InvariantCulture, "products_{0}_index", (object)database.Name); | |
} | |
} |
Thank you!
No comments:
Post a Comment