Indexing

When Connect is installed the default index is patched to exclude all product data and a separate product index is created that contains extended product data.

While synchronizing all products or a list of products, the indexing is stopped. After synchronization finishes the indexes are rebuilt. This is done for performance reasons. The configuration snippet below shows the default configuration of the SynchronizeProductList pipeline containing the processors related to indexing.

<commerce.synchronizeProducts.synchronizeProductList>
<processor type="Sitecore.Commerce.Pipelines.Products.SynchronizeProductList.PauseSearchIndexing, Sitecore.Commerce" />
<processor type="Sitecore.Commerce.Pipelines.Products.SynchronizeProductList.SynchronizeProductList, Sitecore.Commerce" />
<processor type="Sitecore.Commerce.Pipelines.Products.SynchronizeProductList.ResumeSearchIndexing, Sitecore.Commerce" />
<processor type="Sitecore.Commerce.Pipelines.Products.SynchronizeProductList.RebuildSearchIndexes, Sitecore.Commerce" />
</commerce.synchronizeProducts.synchronizeProductList>

In the Sitecore.Commerce.Products.Config file, the setting ProductSynchronization.ProductIndexes contains a comma separated list of index names that are stopped and re-started during product synchronization.

<!-- PRODUCT INDEXES.
The indexes are used to store synchronized products.
Can be stopped, resumed and rebuilt automatically during product synchronization.
-->
<setting name="ProductSynchronization.ProductIndexes" value="sitecore_master_index, commerce_products_master_index" />

Note

If new or custom product templates are introduced, both the DefaultIndexConfiguration and the Product index configurations must be updated.

Warning

If additional indexes are created, the setting must be updated to include the name of the indexes. If not, indexing will continue during synchronization resulting in performance degradation.

By design, the default master and web indexes are configured not to include the items stored in the product repositories.The default index configuration is patched with an Exclude section with an entry for each product template:

<exclude hint="list:ExcludeTemplate">
<ProductRepositoryTemplateId>{F599BF48-D6FE-40DC-9F78-CF2D56BFB657}</ProductRepositoryTemplateId>
            <ProductTemplateId>{47D1A39E-3B4B-4428-A9F8-B446256C9581}</ProductTemplateId>
…
</exclude>

Connect comes with its own product index for both the master and the web database. The index serves several purposes:   

  • To separate content from data in two separate indexes.

    The product index is used, when searching the product repository bucket from within the Content Editor. This is achieved by patching the getContextIndex pipeline.

    <contentSearch.getContextIndex>
    <processor type="Sitecore.Commerce.Pipelines.ContentIndex.CustomIndex.FetchCustomIndex,
    Sitecore.Commerce"                patch:before="processor[@type='Sitecore.ContentSearch.Pipelines.GetContextIndex.FetchIndex,
    Sitecore.ContentSearch']"/>
    </contentSearch.getContextIndex>
  • To include extended product data.

    commerce.inventory.stockStatusForIndexing pipeline reads inventory data per product from the external commerce system and populates the index. Computed fields are used to include the inventory data. The configuration can be found in the Sitecore.Commerce.Products.Lucene.Index.Common.config file. The following table contains an example of the product index extended with four fields:

    • In-Stock—contains a list of locations where the product is in stock.

    • Out of Stock—contains a list of locations where the product is out of stock.

    • Location—contains a list of locations where the product is orderable from.

    • Pre-Orderable—contains a Boolean value indicating whether the product is pre-orderable or not.

Product ID (not variant)

Size

Color

In stock

Out-of-stock

Location

Pre-orderable

Aw123-04

S, M, L, XL

R, B, G, O

Central Store, Store1, Store2

Store3

Central Store 1, Store 2, Store 3

The product index is defined in the Sitecore.Commerce.Products.Lucene.Index.Master.config file. A similar configuration file is defined for the Web index.

<configuration
xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration,
Sitecore.ContentSearch">
   
<indexes hint="list:AddIndex">
        
<index id="commerce_products_master_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex,
Sitecore.ContentSearch.LuceneProvider">
<param
desc="name">$(id)</param>
            <param desc="folder">$(id)</param>
            <!-- This initializes the index property store. Id has to be set to
the index id -->
            <param
desc="propertyStore" ref="contentSearch/databasePropertyStore" param1="$(id)"
/>
            <configuration
ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration"/>
            <strategies
hint="list:AddStrategy">
              <!--
NOTE: Order controls the execution order -->
              <strategy
ref="contentSearch/indexUpdateStrategies/syncMaster" />
            </strategies>
            <commitPolicyExecutor
type="Sitecore.ContentSearch.CommitPolicyExecutor,
Sitecore.ContentSearch">
              <policies
hint="list:AddCommitPolicy">
                <policy
type="Sitecore.ContentSearch.TimeIntervalCommitPolicy,
Sitecore.ContentSearch" />
              </policies>
            </commitPolicyExecutor>
            <locations
hint="list:AddCrawler">
              <crawler
type="Sitecore.Commerce.Search.ProductItemCrawler,
Sitecore.Commerce">
                <Database>master</Database>
                <Root>/sitecore/content/Product Repository</Root>
              </crawler>
            </locations>  
</index>
</indexes>
</configuration>
</contentSearch>
</sitecore>
</configuration>

Note

It is assumed that the product repository is located under the following path /sitecore/content/Product Repository. If this is not the case, the <Root> element for the crawler must be updated to reflect the actual location.

A custom crawler is used for the product index to include the items based on the product templates defined in the <includeTemplates> section of the  Sitecore.Commerce.Products.config configuration file. The list of product templates defined in this section is an exact match of the exclude templates section for the DefaultIndexConfiguration. If a custom product template is introduced, then the index configuration must be updated.

<includeTemplates>
      <ProductRepositoryTemplateId>{F599BF48-D6FE-40DC-9F78-CF2D56BFB657}</ProductRepositoryTemplateId>
      <ProductTemplateId>{47D1A39E-3B4B-4428-A9F8-B446256C9581}</ProductTemplateId>
…
</includeTemplates>