Trigger product index update from code

Is it possible to trigger a product index update (not rebuild) from code? Similar to clicking the “Update” button in BackOffice -> Settings.

Litium version: 6.2.2

You can try Litium.Foundation.Modules.ProductCatalog.ModuleProductCatalog.Instance.ProductIndexingService.RebuildIndex.

Calling this by code sounds that you have a problem that you not got ride of and instead of finding the root cause of the problem this will be a workaround that may lead into other problems.

I want to update the product search index when activating/deactivating campaigns, to be able to add (amongst other things) the campaign price to the index. Is that a bad approach?

You also need to think of how it will work in multiserver environment to get events syncronized correctly. In the accelerator file CampaignEventListener are doing more or less what I think you are trying to build even that it not directly trigger the search index to be updated but trigger an event that the search index is listen to.

Good point. This is a single server environment so we should be good.

Thanks, I’ll take a look at the accelerator!

I think it is good to build all solutions as they should be hosted in a multiserver environment. The reason is that today the customer may be small and only need one server, but tomorrow or the day after that they may need to scale to multiple servers and if the application not is prepared for that from the beginning it will be a large job to make the application running correctly with multiple servers.

What solution would you recommend in this case? What we want to achieve is:

  • adding the campaign price to the product index when a campaign is activated
  • resetting the price when a campaign is deactivated

Is there a smart way to make this happen, which takes a multi server environment into consideration? Also, how does the accelerator reset the prices for products when a campaign is deactivated?

Campaign activation and deactivation is something that only is triggered when you active/deactivate the campaign in BO. The event is not triggered when the campaign enter/exit the time that is set on the campaign that make it hard to save the prices and trust that the saved price is the correct one.

In accelerator we handle this on the way that we index each campaign price into an individual field in the search index. For the search we fetch the active campaigns for the current user and build a filter-statement over them. Sorting will always be in memory to handle and ensure they are sorted regarding to the lowest value in multiple search index fields. Check the accelerator code and use that as a reference to what you want to do.

Where can I find the campaign prices in the index? I took a look at the Product index through Luke (Lucene Index Toolbox) but couldn’t find any campaign prices, only the standard price.

Default Litium installation will not index campaign prices, you will then not find them in the search index.

If you using the accelerator you have the indexing part for campaign prices in the accelerator. Some of the classes is the following where some of them listen on events and build up a cache of the campaign prices for the different variants and some class will add that to the search index as a separate column that have the campaign id in the name.

Similar logic exists for the “Most sold” that will use statistics from orders that will also be added to the search index to be able to sort on that information.