Walkthrough: Including Commerce catalog items in SXA indexes

Current version: 10.2

Starting with Sitecore XC 9.3, the Commerce Engine is responsible for the indexing of catalog entities (catalog items and categories). The index update strategy keeps the Sitecore indexes (sitecore_master_index and sitecore_web_index) up-to-date with the latest catalog items, effectively enabling product search on the SXA Storefront. Sitecore Experience Accelerator (SXA), in contrast, uses different indexes by default (the sitecore_sxa_master_index and sitecore_sxa_web_index) to enable page search on SXA website. But if needed, you can change the default configuration to include Catalog items in the SXA indexes, in addition to page items, instead of the Sitecore master and web indexes.

Note

Two different indexes cannot include the same catalog data set. This limitation does not apply to master and web indexes, as these indexes do not actually contain the same catalog data set.

This walkthrough describes how to:

  • Add the SXA indexes to the Commerce Engine Connect

  • Add the SXA indexes to the GetChildrenToIndex processor

  • Update Commerce Engine search and Solr policies

  • Change the storefront indexing settings in Sitecore

Note

This walkthrough assumes that you have already:

  • Created the required SXA Solr cores as per the instructions on the Solr website to create and initialize a new Solr core.

  • Updated the <SXASite>\App_Config\Modules\SXA\Sitecore.XA.Foundation.Search.Solr.config file accordingly.

Add the SXA indexes to the Commerce Engine Connect indexing configuration

By default, the default content search indexing strategy in CE Connect updates the Sitecore master and web indexes. You must update the Commerce Engine Connect configuration with the name of your custom SXA indexes names.

To add the SXA indexes to the Commerce Engine Connect indexing configuration:

  1. In the inetpub\wwwroot\<site>\App_Config\Include\Y.Commerce.Engine\ folder, open the Sitecore.Commerce.Engine.Connectors.Index.Solr.config.

  2. Locate the section starting with <index id="sitecore_web_index">, and replace the index id value with the name of the SXA web index, for example:

    RequestResponse
    <index id="sitecore_sxa_web_index">
       <strategies hint="list:AddStrategy">
          <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/commerceEngineIntervalAsynchronousStrategyWeb" />
       </strategies>
       <locations hint="list:AddCrawler">
          <crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.CommerceEngineCrawler, Sitecore.Commerce.Engine.Connect">
            <ListName>SitecoreItemIndexingWeb</ListName>
          </crawler>
       </locations>
     </index>
  3. Add the custom SXA Master index to the configuration. Copy and paste the existing block that defines the <index id="sitecore_master_index"> configuration, and then change the index ID to <index id="sitecore_sxa_master_index">.

    For example:

    RequestResponse
    <index id="sitecore_sxa_master_index">
       <strategies hint="list:AddStrategy">
          <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/commerceEngineIntervalAsynchronousStrategyMaster" />
       </strategies>
       <locations hint="list:AddCrawler">
         <crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.CommerceEngineCrawler, Sitecore.Commerce.Engine.Connect">
             <ListName>SitecoreItemIndexingMaster</ListName>
         </crawler>
       </locations>
    </index>
  4. Save your changes.

Add the SXA indexes to the GetChildrenToIndex processor

You must add your custom SXA indexes to a list of indexes in the Sitecore.Commerce.Engine.Connect.Pipelines.GetChildrenToIndex processor. This processor stops the Sitecore index crawler from unnecessarily indexing Commerce items again, because Sitecore XC implements its own crawler to index Commerce items.

To add the custom SXA indexes to the processor:

  1. In the C:\inetpub\wwwroot\<CommerceEngine>\App_Config\Include\Y.Commerce.Engine folder, open the Sitecore.Commerce.Engine.Connectors.Index.Common.config file.

  2. Add the custom SXA Master and SXA Web indexes to the list of indexes as shown in the following example:

    RequestResponse
    <pipelines>
      <indexing.getChildrenToIndex>
         <!-- 
              Insert our processor first so that we can intercept Commmerce items that we do not want indexed into the below referenced indexes.
              As Commerce uses a separate crawler to index Commerce items, we insert this processor to stop the default crawlers from attempting to index
              Commerce items.
              By default the processor below will skip indexing of children of the following locations or templates:
                Commerce Catalog Folder   ID {334E2B54-F913-411D-B159-A7B16D65242C}
         -->     <processor type="Sitecore.Commerce.Engine.Connect.Pipelines.GetChildrenToIndex, Sitecore.Commerce.Engine.Connect" patch:source="Sitecore.Commerce.Engine.Connectors.Index.Common.config">
            <!-- The list of indexes that we do not want commerce items to be indexed to -->
            <Indexes hint="list:AddString" help="Add index names below to stop crawling of Commerce items by the default crawler">
              <IndexName>sitecore_master_index</IndexName>
              <IndexName>sitecore_web_index</IndexName>
              <IndexName>sitecore_testing_index</IndexName>
              <IndexName>sitecore_suggested_test_index</IndexName>
              <IndexName>sitecore_sxa_master_index</IndexName>
              <IndexName>sitecore_sxa_web_index</IndexName>
      </Indexes

Update Commerce Engine search and Solr policies

You must update the index names in the Commerce Engine search and Solr policy sets.

To update Commerce Engine search and Solr policies:

  1. Open the C:\inetpub\wwwroot\<CommerceEngine>\wwwroot\data\Environments\PlugIn.Search.PolicySet-1.0.0.json file.

  2. Make the following changes:

    • Search for "Name": "<site>_web_index", and change the value to match the name of the SXA Web index, for example "<site>_sxa_web_index".

    • Search for "Name": "<site>_master_index", and change the value to match the name of the SXA Master index, for example "<site>_sxa_master_index".

    • Search for "InternalIndexName": "sitecore_web_index", and change the value match the name of the your SXA Web index, for example "sitecore_sxa_web_index".

    • Search for "InternalIndexName": "sitecore_master_index" and change the value to match the value of the SXA Master index, for example "sitecore_sxa_master_index".

  3. Open the C:\inetpub\wwwroot\<CommerceEngine>\wwwroot\data\Environments\PlugIn.Search.Solr.PolicySet-1.0.0.json file.

  4. Make the following changes:

    • Search for "IndexName": "sitecore_web_index", and change the value to match the name of the name of the SXA Web index, for example "sitecore_sxa_web_index".

    • Search for "IndexName": "sitecore_master_index", and change the value to match the name of the SXA Master index, for example "sitecore_sxa_master_index".

    • Search for "SearchScopeName": "<site>_web_index", and change the value to match the name of the SXA Web index, for example "<site>_sxa_web_index"

    • Search for "SearchScopeName": "<site>_master_index", and change the value to match the name of the SXA Master index, for example "<site>_sxa_master_index"

  5. Save your changes.

  6. Bootstrap the Commerce Engine to register your configuration changes.

  7. In IIS Manager, perform an IIS reset.

  8. Clear the Redis cache.

Change the storefront indexing settings in Sitecore

To change the storefront indexing configuration to use SXA indexes:

  1. Log in to Sitecore.

  2. In the Content Editor, navigate to the Sitecore/Storefront/Settings/Site Grouping/Storefront item.

  3. In the Indexing section, update the index names to reflect the name of your SXA Web and Master indexes.

    For example:

  4. Publish the website.

  5. Rebuild the SXA Master and Web indexes.

Do you have some feedback for us?

If you have suggestions for improving this article,