December 12, 2018
When you use Optimizely Commerce, your products will often be imported from an external source. When you use Optimizely Find and there are a lot of changes, the import process might take a while and a lot of requests to Optimizely Find will be made.
So usually you would turn off the Optimizely Find events when starting the import like so:
EventedIndexingSettings.Instance.EventedIndexingEnabled = false;
EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = false;
The problem with this is that your Find index will not be updated and you would need to re-index your site after the import has completed.
You can use the search client to update your index though after all products have been imported.
You keep track of objects that have been changed, added or deleted in an IEnumerable and tell the search client to index or remove them
private static void AddToIndex(IEnumerable itemsToAdd, IClient searchClient)
{
searchClient.Index(objectsToIndex: itemsToAdd);
}
private static void RemoveFromIndex(IEnumerable itemsToRemove, IClient searchClient)
{
RemoveFromIndex(itemsToRemove.Select(p => p.ContentLink), searchClient: searchClient);
}
private static void RemoveFromIndex(IEnumerable itemsToRemove, IClient searchClient)
{
FilterBuilder deleteFilterBuilder =
new FilterBuilder(client: searchClient);
deleteFilterBuilder = itemsToRemove.Aggregate(
seed: deleteFilterBuilder,
func: (current, contentLink) => current.Or(x => <span data-mce-type="bookmark" id="mce_SELREST_start" data-mce-style="overflow:hidden;line-height:0" style="overflow:hidden;line-height:0;"></span>x.ContentLink.Match(contentLink)));
searchClient.Delete(filter: deleteFilterBuilder);
}
Depending on the amount of products you might need to use batches for the add and delete.
After you have done this you need to enable the events again.
You can find the complete sample here.
Original article posted on Optimizely Deleopment: Speed up your product imports