Sitecore Lucene:在更新项目时重新索引子项(或父项)

时间:2011-11-24 09:17:00

标签: database lucene indexing sitecore web-crawler

场合

我有以下Sitecore Lucene配置:

  • 新索引,type =“Sitecore.Search.Index,Sitecore.Kernel”
  • 包含两个抓取工具(添加额外“计算”字段的自定义抓取工具)
  • 每个抓取工具处理其特定模板GUID,因为它们包含不同的计算字段

问题

计算字段基于父/子字段。如何设置Sitecore中的Lucene,只是在索引中更新了实际更改的项目的文档

因此,其他文件上的计算字段(必需,这些字段上有搜索条件)不会更新。

问题

是否有可能手动触发索引中其他项目的更新?
我已经研究过继承Sitecore.Search.Index,但没有一个相关的方法是虚拟的。

另外,我尝试订阅IndexingProvider-events:
公共事件EventHandler OnRemoveItem;
公共事件EventHandler OnRemoveVersion;
公共事件EventHandler OnUpdateItem;

这背后的想法是在DatabaseCrawler中触发需要更新的其他项目的OnUpdateItem事件,但是您无法从IndexingProvider外部触发此事件。

有没有办法在不进行完全重建的情况下触发索引更新,这不涉及保存/重新发布其他项目?

谢谢!
桑德

1 个答案:

答案 0 :(得分:4)

索引更新是通过HistoryEngine触发的,其事件和方法是公共的,因此您可以利用历史引擎上的事件处理程序来检测何时发生需要重新索引的更改,然后将其他条目添加到历史记录中您需要重新索引的父/子项目。

Sitecore.Data.Managers.IndexingManager.InitializeEventHandlers()有一个将处理程序附加到数据库的HistoryEngine的示例。

然后你的处理程序逻辑就像

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);
}

附加此信息的最佳位置可能是initialize管道。

N.B。这是一个未经考验的想法,请报告您的结果!

相关问题