在全球范围内排除克隆了索引项?(Globally exclude cloned items from

2019-09-29 14:40发布

我在寻找一种优雅的方式来排除从我的网站索引的克隆项目。 我有项目出现在我的搜索结果重复。 我喜欢它,如果只有原来的项目出现,根本没有克隆。

浮现在脑海中的一些可能的解决方案是:

  1. 创建一个Global Item Boosting Rule大幅降低增压值,如果项目的_Source字段不为空。 这不是优选的,因为它不仅降低了成绩,并且不从搜索结果中去除的克隆。

  2. 排除每个查询中克隆的项目,我执行使用扩展Where子句。 这也不是优选的,因为这意味着我需要记住,包括所有的查询,这个条款。 此外,克隆的项目仍然在索引中。

Sitecore的V7.1

Answer 1:

我的做法是这样的:

public class InboundIndexFilter : InboundIndexFilterProcessor
{
    public override void Process(InboundIndexFilterArgs args)
    {
        var item = args.IndexableToIndex as SitecoreIndexableItem;

        if (item != null && (!item.Item.Versions.IsLatestVersion() || item.Item.IsClone))
        {
            args.IsExcluded = true;
        }
    }
}

它会跳过克隆和非最新版本。 然后,我更新了相应的管道设置:

 <indexing.filterIndex.inbound>
    <processor type="XY.InboundIndexFilter, X.Y.Z"/>
 </indexing.filterIndex.inbound>

更多关于入站过滤器



Answer 2:

您可以创建一个自定义的履带式和逻辑添加到该排除克隆项目。
我想的方法是创建一个从继承的类Sitecore.ContentSearch.SitecoreItemCrawler和覆盖DoAdd()方法。
事情是这样的:

protected override void DoAdd(IProviderUpdateContext context, SitecoreIndexableItem indexable)
{
    Assert.ArgumentNotNull((object) context, "context");
    Assert.ArgumentNotNull((object) indexable, "indexable");

    if (!indexable.Item.IsClone)
    {
        base.DoAdd(context, indexable);
    }
}

然后,你需要设置你的履带配置为使用自定义爬虫。
Sitecore.ContentSearch.<Lucene/Solr>.Index.<databasename>.config文件可以定义使用哪个爬虫。
您需要更新contentSearch/configuration/indexes/locations/crawler有元素并指向你的类。



文章来源: Globally exclude cloned items from index?