protected virtual void UpdateIndex(BulkLoadContext context, ICollection <ItemChange> itemChanges, Database database, ISearchIndex index) { BaseJob job = null; var indexSummary = index.RequestSummary(); if (indexSummary == null) { context.Log.Warn($"Skipping updating index '{index.Name}' because we could not get its summary."); return; } if (!context.ShouldUpdateIndex(index, indexSummary)) { context.Log.Warn($"Skipping updating index '{index.Name}' because it's empty."); return; } var touchedPercentage = (uint)Math.Ceiling((double)itemChanges.Count / Math.Max(1, indexSummary.NumberOfDocuments) * 100); if (context.IndexRebuildThresholdPercentage.HasValue && touchedPercentage > context.IndexRebuildThresholdPercentage.Value) { context.Log.Info($"Rebuilding index '{index.Name}' because {touchedPercentage}% is changed."); job = IndexCustodian.FullRebuild(index); } else if (context.Destination != null && !itemChanges.Any(ic => ic.Deleted) && // Refresh doesn't do deletes. context.IndexRefreshThresholdPercentage.HasValue && touchedPercentage > context.IndexRefreshThresholdPercentage.Value) { context.Log.Info( $"Refreshing index '{index.Name}' from '{context.Destination.ItemPath}' because {touchedPercentage}% is changed."); job = IndexCustodian.Refresh(index, new SitecoreIndexableItem(database.GetItem(new ID(context.Destination.ItemId)))); } else { var sitecoreIds = GetItemsToIndex(itemChanges, database); context.Log.Info($"Updating index '{index.Name}' with {sitecoreIds.Count} items."); job = IndexCustodian.IncrementalUpdate(index, sitecoreIds); } job.Wait(); }