EngelbertCoder
EngelbertCoder

Reputation: 797

Sitecore Lucene Search Exclude Item

in Sitecore Lucene Search, we can exclude a template from search with the following web.config tag :

<include hint="list:ExcludeTemplate"> 
     <template>{8C18027D-CA51-4E5D-A7C1-510965555C}</template>  
</include>

My question is :

How can we exclude a specific item from the search using web.config.

Is there a tag like :

<include hint="list:ExcludeItem"> 

I searched the web but could not find it. The solution and a related reference would be appreciated.

Thanx

Upvotes: 0

Views: 1417

Answers (2)

Pascal Mathys
Pascal Mathys

Reputation: 609

You can extend the crawler to support this type of configuration. My company extended the Sitecore search contrib module of Alex Shyba to support the inclusion and exclusion of item paths with <include hint="list:IncludePath"> and <include hint="list:ExcludePath">

You can find the specific code in that class: https://github.com/unic/SitecoreSearchContrib/blob/master/scSearchContrib.Crawler/Crawlers/AdvancedDatabaseCrawler.cs

This is only a starter, but with that you can make a deep and clean integration into the crawler. The approach of Trayek would work too.

Upvotes: 0

Trayek
Trayek

Reputation: 4410

Not sure if it's possible to do through the web.config, but you could have a checkbox on your templates which if it's checked it won't be added to the index?

That would mean a custom crawler though, which would do something like:

public class CustomCrawler : DatabaseCrawler
{
    protected override bool IsMatch(Item item)
    {
        if (MainUtil.GetBool(item["include in search"], false))
        {
            return false;
        }

        return base.IsMatch(item);
    }
}

Upvotes: 4

Related Questions