防止项目的空语言版本被编入索引
Prevent empty language versions of items from getting indexed
我们的解决方案中有 20 多种语言,每当我们上传新媒体或 create/edit Sitecore 项目时,索引过程都很慢。项目的空语言版本正在被索引,这大大减慢了索引速度。有没有办法防止项目的空语言版本被编入索引?我猜应该有一个管道,我可以利用它来拦截空项目并防止它们被编入索引。
此外,阻止空版本索引会不会产生意想不到的后果?
谢谢
如果您需要在索引时过滤掉空项目,您可以尝试其中一种入站过滤管道处理器。 (虽然此解决方案仅适用于 Sitecore 7+ 版本)
以上 link 现在已损坏,可以在此处找到类似的文档:https://doc.sitecore.com/SdnArchive/upload/sitecore7/75/sitecore_search_and_indexing_guide_sc75-usletter.pdf
在处理器中,您可以检查被索引的项目是否有该项目语言的版本,并将 IsExcluded 属性 更新为 false。
只要您从索引中获取结果的代码可以处理它,我预计过滤掉空项目不会有任何问题。
为了跟进和详细说明 IsExcludedFromIndex
属性,我将提供一些示例。让我们使用一个示例索引定义:
<index id="homepage_nodes_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
<param desc="name">$(id)</param>
<param desc="folder">$(id)</param>
<!-- This initializes index property store. Id has to be set to the index id -->
<param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
<strategies hint="list:AddStrategy">
<!-- NOTE: order of these is controls the execution order -->
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/intervalAsyncMaster" />
</strategies>
<locations hint="list:AddCrawler">
<!--<crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">-->
<crawler type="Custom.Webcms.SitecoreUtil.Crawlers.customItemCrawler, Custom.Webcms.Sitecore">
<Database>master</Database>
<Root>/sitecore/content</Root>
</crawler>
</locations>
您可以在这里看到默认的爬虫 class 已被自定义爬虫 class 替换。
您将像这样创建子class:
public class CustomItemCrawler : SitecoreItemCrawler
并像这样覆盖 IsExcludedFromIndex
属性:
protected override bool IsExcludedFromIndex(SitecoreIndexableItem indexable, bool checkLocation = false)
{
Item obj = (Item)indexable;
Assert.ArgumentNotNull((object)obj, "item");
IDocumentBuilderOptions documentOptions = this.DocumentOptions;
Assert.IsNotNull((object)documentOptions, "DocumentOptions");
if (!obj.Database.Name.Equals(this.Database, StringComparison.InvariantCultureIgnoreCase))
{
Event.RaiseEvent("indexing:excludedfromindex", (object)this.index.Name, (object)obj.Uri);
return true;
}
else if (checkLocation && !this.RootItem.Axes.IsAncestorOf(obj))
{
Event.RaiseEvent("indexing:excludedfromindex", (object)this.index.Name, (object)obj.Uri);
return true;
}
else if (...)
{
Event.RaiseEvent("indexing:excludedfromindex", (object)this.index.Name, (object)obj.Uri);
return true;
}
else
{
if (!documentOptions.ExcludedTemplates.Contains(obj.TemplateID.ToString()))
return false;
Event.RaiseEvent("indexing:excludedfromindex", (object)this.index.Name, (object)obj.Uri);
return true;
}
}
我们的解决方案中有 20 多种语言,每当我们上传新媒体或 create/edit Sitecore 项目时,索引过程都很慢。项目的空语言版本正在被索引,这大大减慢了索引速度。有没有办法防止项目的空语言版本被编入索引?我猜应该有一个管道,我可以利用它来拦截空项目并防止它们被编入索引。
此外,阻止空版本索引会不会产生意想不到的后果?
谢谢
如果您需要在索引时过滤掉空项目,您可以尝试其中一种入站过滤管道处理器。 (虽然此解决方案仅适用于 Sitecore 7+ 版本)
以上 link 现在已损坏,可以在此处找到类似的文档:https://doc.sitecore.com/SdnArchive/upload/sitecore7/75/sitecore_search_and_indexing_guide_sc75-usletter.pdf
在处理器中,您可以检查被索引的项目是否有该项目语言的版本,并将 IsExcluded 属性 更新为 false。
只要您从索引中获取结果的代码可以处理它,我预计过滤掉空项目不会有任何问题。
为了跟进和详细说明 IsExcludedFromIndex
属性,我将提供一些示例。让我们使用一个示例索引定义:
<index id="homepage_nodes_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
<param desc="name">$(id)</param>
<param desc="folder">$(id)</param>
<!-- This initializes index property store. Id has to be set to the index id -->
<param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
<strategies hint="list:AddStrategy">
<!-- NOTE: order of these is controls the execution order -->
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/intervalAsyncMaster" />
</strategies>
<locations hint="list:AddCrawler">
<!--<crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">-->
<crawler type="Custom.Webcms.SitecoreUtil.Crawlers.customItemCrawler, Custom.Webcms.Sitecore">
<Database>master</Database>
<Root>/sitecore/content</Root>
</crawler>
</locations>
您可以在这里看到默认的爬虫 class 已被自定义爬虫 class 替换。
您将像这样创建子class:
public class CustomItemCrawler : SitecoreItemCrawler
并像这样覆盖 IsExcludedFromIndex
属性:
protected override bool IsExcludedFromIndex(SitecoreIndexableItem indexable, bool checkLocation = false)
{
Item obj = (Item)indexable;
Assert.ArgumentNotNull((object)obj, "item");
IDocumentBuilderOptions documentOptions = this.DocumentOptions;
Assert.IsNotNull((object)documentOptions, "DocumentOptions");
if (!obj.Database.Name.Equals(this.Database, StringComparison.InvariantCultureIgnoreCase))
{
Event.RaiseEvent("indexing:excludedfromindex", (object)this.index.Name, (object)obj.Uri);
return true;
}
else if (checkLocation && !this.RootItem.Axes.IsAncestorOf(obj))
{
Event.RaiseEvent("indexing:excludedfromindex", (object)this.index.Name, (object)obj.Uri);
return true;
}
else if (...)
{
Event.RaiseEvent("indexing:excludedfromindex", (object)this.index.Name, (object)obj.Uri);
return true;
}
else
{
if (!documentOptions.ExcludedTemplates.Contains(obj.TemplateID.ToString()))
return false;
Event.RaiseEvent("indexing:excludedfromindex", (object)this.index.Name, (object)obj.Uri);
return true;
}
}