Globally exclude cloned items from index?

我怕爱的太早我们不能终老 提交于 2019-12-11 08:35:29

问题


I am looking for an elegant way to exclude cloned items from my web index. I am having items appear as duplicates in my search results. I'd prefer it if only the original items appear and no clones at all.

Some possible solutions that come to mind are to:

  1. Create a Global Item Boosting Rule to drastically lower the boost value if the item's _Source field is not empty. This is not preferred as it only lowers the score and does not remove the clones from the search results.

  2. Exclude the cloned items in every query that I perform using an extended Where clause. This is also not preferred as it means that I need to remember to include this clause on all queries. Furthermore, the cloned items still remain in the index.

Sitecore v7.1


回答1:


My approach is like this:

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

It skips clones and non-latest versions. Then I updated the corresponding pipeline settings:

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

More about inbound filters




回答2:


You can create a custom crawler and add logic into that to exclude items that are cloned.
The approach I'm thinking of would be to create a class that inherits from Sitecore.ContentSearch.SitecoreItemCrawler and override the DoAdd() method.
Something like this:

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

Then you need to setup your crawler config to use your custom crawler.
In the Sitecore.ContentSearch.<Lucene/Solr>.Index.<databasename>.config file you define which crawlers are used.
You need to update the contentSearch/configuration/indexes/locations/crawler element and point to you class there.



来源:https://stackoverflow.com/questions/20646719/globally-exclude-cloned-items-from-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!