Solr Index Update

Backoffice handles its Solr index integrity when you change data both within and from outside of the application.

Index Update Overview

In Backoffice, an index updating strategy tracks and handles changes made by a user in the UI on items of any type included in Backoffice Solr index at runtime. The strategy doesn't track changes made by background jobs. The default strategy updates Solr index immediately, but you can alter this behavior with the appropriate spring configuration.

You can also use the update-backofficeIndex-CronJob that serves to track data changes made from outside of Backoffice application to the indexed types. By default, the CronJob runs every minute and modifies all the modified entities.

Indexing Strategies

To keep Solr index up-to-date, Backoffice uses aspect-oriented programming to intercept persistent operations that result in data changes. The declaration of the relevant aspects is as follows:

<alias name="defaultSolrHotUpdater" alias="solrHotUpdater" />
<bean id="defaultSolrHotUpdater" class="com.hybris.backoffice.solrsearch.aspects.ObjectFacadeSolrIndexingAspect" >
	<property name="modelService" ref="modelService" />
	<property name="solrIndexSynchronizationStrategy" ref="solrIndexSynchronizationStrategy" />
	<property name="itemModificationHistoryService" ref="itemModificationHistoryService" />
	<property name="configurationService" ref="configurationService" />
</bean>
				
<aop:config>
	<aop:aspect id="solrIndexHotUpdaterAspect" ref="solrHotUpdater" >
		<aop:after-returning pointcut-ref="objectsModifiedByFacade" method="updateChanged" returning="retVal" />
		<aop:after-returning pointcut-ref="objectsRemovedByFacade" method="updateRemoved" returning="retVal" />
		<aop:before pointcut-ref="objectsRemovedDuringSync" method="updateRemovedForMethodParameter"/>
	</aop:aspect>
</aop:config>

The defaultSolrHotUpdater bean uses the solrIndexSynchronizationStrategy to perform the index update. The defaultSolrIndexSynchronizationStrategy, which is the standard implementation of the bean, uses the direct index update strategy: com.hybris.backoffice.solrsearch.events.DirectSolrIndexSynchronizationStrategy. The strategy has the following characteristics:

  • Solr index is always up-to-date.
  • Solr index update happens synchronously, which leads to idle UI for bigger datasets.

However, if your requirements are different, you can consider implementing an alternative strategy that serves your business needs.

To replace the default indexing strategy with your custom one, complete the following steps:

  1. Provide a custom implementation of the com.hybris.backoffice.solrsearch.events.SolrIndexSynchronizationStrategy.
  2. Register the implementation as a Spring bean and override the alias. See the example:
    <alias name="customSynchronizationStrategy" alias="solrIndexSynchronizationStrategy"/>
    <bean name="customSynchronizationStrategy"
    	class="com.your.company.your.pckg.CustomSynchronizationStrategy">
    	<!-- bean config -->
    </bean>

Solr Index Hot Update

The default configuration in Backoffice sets triggering Solr index update on every change of Product model. The hot update operation blocks UI to ensure that users see accurate search results at any time.

However, with bigger catalogs, you can change this default behavior. You can configure Solr index updates in Backoffice so that the system performs the update in a nonblocking manner. Solr indexing happens as a background operation, but with a cost that the search results aren’t fully accurate until the indexer job is completed.

To configure Solr indexing as a background process, set the following property in local.properties to true:

backoffice.search.background.solr.indexing.enabled=true

Solr Index Commit and Optimization Strategies

Keeping Solr index up-to-date and optimized is crucial to keep Backoffice application fast and responsive.

The approach to keeping index up-to-date is highly project-specific. Choose the best strategy basing on your business model and data characteristics.

There are three strategies you can use to keep the index optimized:
  • Platform – Solr commit and optimize operations are bound to indexing operations managed by Platform. In such cases, you can trigger them after every index modification. For some specific scenarios, it’s convenient. In general, avoid such an approach as both commit and optimization are slow and expensive operations.

    By default, the Solr indexer configuration in Backoffice sets the Commit mode to AFTER_INDEX and Optimize mode to NEVER.

    To change this configuration, in Backoffice navigate to Start of the navigation pathSystem Next navigation step Facet Search Next navigation step Facet Search ConfigEnd of the navigation path, go to Solr Config for Backoffice, and click indexConfig-Backoffice field in Properties tab to edit the details. The modal window appears:

  • Solr autocommit – autocommit is a built-in Solr feature, which you can tune in details in the solrconfig.xml file.

    For more information, see the Update Handler SectionInformation published on non-SAP site.

  • CronJobs – when available configuration options aren’t sufficient, you can implement further customization using Platform CronJob mechanism.

    For more information, see the The CronJob Service.