thadmiller
thadmiller

Reputation: 659

Sitecore 7.2 and SOLR: exclude clones from web index

I'm trying to exclude all clones from Sitecore's web index. I've created a custom crawler inheriting from Sitecore.ContentSearch.SitecoreItemCrawler overriding the IsExcludedFromIndex method with the following code:

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

My "Hide from Search" field works: any items with that field set are not included in the web index. However, the indexable.Item.IsClone is never true, and all "clones" remain in the web index.

When I run the master index against this crawler, the IsClone is true for each clone and they are not included in the index. I suspect it works for master and not for the web index because clones are expanded on publishing targets (as noted by John West).

Apologies if this question is considered a duplicate of Globally exclude cloned items from index? - the solution there did not work for me, and I'm using SOLR (vs Lucene) and on a newer version of Sitecore, so I believe this may be a separate issue.

So, how can I exclude all clones from a SOLR index of a Sitecore 7.2 web (publish target) database?

Upvotes: 1

Views: 295

Answers (1)

Marek Musielak
Marek Musielak

Reputation: 27142

As you wrote in your question, IsClone property is not relevant for items which are published, cause Sitecore clears the value of __Source field.

That's why there is no out of the box method to determine whether the item from the web database was a clone or not.

What you can use is the solution proposed by John West in his blog post Identify Cloned Items Sitecore ASPNET CMS Publishing Target Databases. In nutshell, you need to add your processor to the publishing pipeline, and save the value of the __Source field in another custom field or at least store boolean value in your custom Is Cloned field.

Then you can use your approach, just instead of checking IsClone you need to check whether new custom field is not empty.

Upvotes: 2

Related Questions