On a site powered by Sitecore 6.2, I need to give the user the ability to selectively exclude items from search results.
To accomplish this, I have added a checkbox field entitled "Include in Search Results", and I created a custom database crawler to check that field's value:
~\App_Config\Include\Search Indexes\Website.config:
<search>
<configuration type="Sitecore.Search.SearchConfiguration, Sitecore.Kernel" singleInstance="true">
<indexes hint="list:AddIndex">
<index id="website" singleInstance="true" type="Sitecore.Search.Index, Sitecore.Kernel">
...
<locations hint="list:AddCrawler">
<master type="MyProject.Lib.Search.Indexing.CustomCrawler, MyProject">
...
</master>
<!-- Similar entry for web database. -->
</locations>
</index>
</indexes>
</configuration>
</search>
~\Lib\Search\Indexing\CustomCrawler.cs:
using Lucene.Net.Documents;
using Sitecore.Search.Crawlers;
using Sitecore.Data.Items;
namespace MyProject.Lib.Search.Indexing
{
public class CustomCrawler : DatabaseCrawler
{
/// <summary>
/// Determines if the item should be included in the index.
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
protected override bool IsMatch(Item item)
{
if (item["include in search results"] != "1")
{
return false;
}
return base.IsMatch(item);
}
}
}
What's interesting is, if I rebuild the index using the Index Viewer application, everything behaves as normal. Items whose "Include in Search Results" checkbox is not checked will not be included in the search index.
However, when I use the search index rebuilder in the Sitecore Control Panel application or when the IndexingManager auto-updates the search index, all items are included, regardless of the state of their "Include in Search Results" checkbox.
I've also set numerous breakpoints in my custom crawler class, and the application never hits any of them when I rebuild the search index using the built-in indexer. When I use Index Viewer, it does hit all the breakpoints I've set.
How do I get Sitecore's built-in indexing processes to respect my "Include in Search Results" checkbox?