Sitecore Lucene: re-specify child (or parent) items in the item being updated

Situation

I have the following Sitecore Lucene configuration:

  • New index, type = "Sitecore.Search.Index, Sitecore.Kernel"
  • Contains two crawlers (a custom crawler that adds additional β€œcalculated” fields)
  • Each crawler processes its own template GUID, because it contains different calculated fields.

Problem

The calculated fields are based on the parent / child fields. As Lucene in Sitecore seems to be configured, only that only documents for items that have actually been changed are updated in the index.

Thus, the calculated fields on other documents (which are required, there are search terms in these fields) are not updated.

Question

Is it possible to manually initiate the update of other elements in the index?
I studied the inheritance of Sitecore.Search.Index, but none of the corresponding methods are virtual.

In addition, I tried to subscribe to IndexingProvider-events:
public event EventHandler OnRemoveItem;
public event EventHandler OnRemoveVersion;
public event EventHandler OnUpdateItem;

The idea was to trigger the OnUpdateItem event in the DatabaseCrawler for other items that need to be updated, but you cannot fire this event from outside the IndexingProvider.

Is there a way to initiate an index update without a complete rebuild that does not include saving / republishing these other elements?

Thanks!
Sander

+6
source share
1 answer

An index update is triggered through HistoryEngine, whose events and methods are publicly available, so you can potentially use the event handler in the history engine to detect when a change occurs that requires reindexing, and then add additional entries to the history for the parent / child elements that you need reindex.

Sitecore.Data.Managers.IndexingManager.InitializeEventHandlers() has an example of attaching a handler to a HistoryEngine database.

Then the logic of your handler will be similar to

 protected void HistoryEngine_AddedEntry(object sender, HistoryAddedEventArgs e) { Item item = e.Database.GetItem(e.Entry.ItemId); //TODO: Add logic to make sure e.Entry.ItemId requires a parent/child reindex as well //TODO: Make sure that logic also prevents excessive or infinite recursion since we'll be triggering the AddedEntry event again below Item parent = item.Parent; //RegisterItemSaved doesn't appear to do anything with its second argument e.Database.Engines.HistoryEngine.RegisterItemSaved(parent, null); } 

The best place to join is probably in the initialize pipeline.

NB is an unverified idea, please report your results!

+4
source

Source: https://habr.com/ru/post/902286/


All Articles