Sandun Perera
Sandun Perera

Reputation: 571

How to update a single item in a Sitecore index?

In my Sitecore content tree there are few thousands of items, and I just want to alter few items programmatically. Instead of rebuilding the entire lucene index which is taking a big time, I want to update index entries for each item I'm altering in real time. I tried

item.Database.Indexes.UpdateItem(item);

but it is obsolete and ask me to use SearchManager.

Can anyone guide me how to update index entries for a given item?

PS: I'm altering items from desktop application, not the website.

Upvotes: 3

Views: 2983

Answers (2)

Michael Baranov
Michael Baranov

Reputation: 809

Well actually there is no Update operation on indexes, so feel free to do delete/add

Upvotes: -1

Marek Musielak
Marek Musielak

Reputation: 27132

Try to execute one of the HistoryEngine.RegisterItem... methods, e.g:

item.Database.Engines.HistoryEngine.RegisterItemSaved(item, new ItemChanges(item));
item.Database.Engines.HistoryEngine.RegisterItemCreated(item);
item.Database.Engines.HistoryEngine.RegisterItemMoved(item, oldParentId);

Upvotes: 5

Related Questions