Sitecore 7.2 和 SOLR:从 Web 索引中排除克隆

Sitecore 7.2 and SOLR: exclude clones from web index

我试图从 Sitecore 的网络索引中排除所有克隆。我创建了一个继承自 Sitecore.ContentSearch.SitecoreItemCrawler 的自定义爬虫,使用以下代码覆盖 IsExcludedFromIndex 方法:

protected override bool IsExcludedFromIndex(SitecoreIndexableItem indexable, bool checkLocation)
{
    if (indexable.Item["Hide from Search"] == "1")
        return true;
    if (indexable.Item.IsClone)
        return true;
    return base.IsExcludedFromIndex(indexable, checkLocation);
}

我的 "Hide from Search" 字段有效:具有该字段集的任何项目都不包含在 Web 索引中。但是,indexable.Item.IsClone 永远不会为真,所有 "clones" 都保留在网络索引中。

当我 运行 针对此爬虫的主索引时,每个克隆的 IsClone 都是正确的,它们不包含在索引中。我怀疑它适用于 master 而不是 web 索引,因为克隆在发布目标上得到了扩展 (as noted by John West)。

如果这个问题被认为是 Globally exclude cloned items from index? 的重复,我深表歉意 - 那里的解决方案对我不起作用,我正在使用 SOLR(与 Lucene 相比)和更新版本的 Sitecore,所以我相信这可能是一个单独的问题。

那么,如何从 Sitecore 7.2 网络(发布目标)数据库的 SOLR 索引中排除所有克隆?

正如您在问题中所写,IsClone 属性 与已发布的项目无关,因为 Sitecore 清除了 __Source 字段的值。

这就是为什么没有开箱即用的方法来确定 Web 数据库中的项目是否为克隆的原因。

你可以使用John West在他的博客post Identify Cloned Items Sitecore ASPNET CMS Publishing Target Databases中提出的解决方案。简而言之,您需要将处理器添加到发布管道,并将 __Source 字段的值保存在另一个自定义字段中,或者至少将布尔值存储在您的自定义 Is Cloned 字段中。

然后你可以使用你的方法,而不是检查 IsClone 你需要检查新的自定义字段是否不为空。