【问题标题】:Globally exclude cloned items from index?从索引中全局排除克隆项目?
【发布时间】:2013-12-17 23:22:03
【问题描述】:

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

想到的一些可能的解决方案是:

  1. 如果项目的 _Source 字段不为空,则创建一个 Global Item Boosting Rule 以大幅降低提升值。 这不是首选,因为它只会降低分数并且不会删除从搜索结果中克隆。

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

Sitecore v7.1

【问题讨论】:

    标签: sitecore lucene.net sitecore7


    【解决方案1】:

    您可以创建自定义爬虫并在其中添加逻辑以排除克隆的项目。
    我正在考虑的方法是创建一个继承自 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 元素并指向您所在的类。

    【讨论】:

    • 我想补充一点,您可能想要改写 IsExcludedFromIndex。对于您要实现的目标来说,这更能说明问题。然而,这两种解决方案都可以工作。
    • 感谢詹斯的建议!
    • Sitecore.ContentSearch.SitecoreItemCrawler 似乎是密封类,还有其他爬虫类可以继承吗?
    • 尝试从 Sitecore.ContentSearch.LuceneProvider.Crawlers.LuceneDatabaseCrawler 继承。我记得 Sc7 开发团队告诉我们应该使用它。我在这里写了关于索引机制的博客:partechit.nl/nl/blog/2013/04/…
    • 您可以使用 SitecoreItemCrawler,但需要更新到 Sitecore 的更新版本。密封的类是一个错误,在 Sitecore 7 的修订版 131127 和 Sitecore 7.1 中也得到了修复。
    【解决方案2】:

    我的做法是这样的:

    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>
    

    More about inbound filters

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-12
      • 1970-01-01
      • 2015-08-04
      • 2016-11-30
      • 2013-11-27
      • 1970-01-01
      • 2018-08-31
      • 2012-10-17
      相关资源
      最近更新 更多