This is a generic situation most of Sitecore geeks face during their development work. Though, you may find several solutions over the internet, but what I am going to put here is the most simple and robust solution.
Just a checkbox and few lines of code and you are done. Let’s do it now.
- add a checkbox field on the item template or on the base template ( your choice) , name it something meaningful like “ExcludeFromSearch” or “DoNotIndex”
- Create a custom item crawler. see the code below
public class CustomItemCrawler : SitecoreItemCrawler
protected override bool IsExcludedFromIndex(SitecoreIndexableItem
indexable, bool checkLocation = false)
var isExcluded = base.IsExcludedFromIndex(indexable, checkLocation);
Item item = indexable;return (item[new ID(pass the checkbox field id here)] == "1") ? true: false;
protected override bool IndexUpdateNeedDelete(SitecoreIndexableItem
var needDelete = base.IndexUpdateNeedDelete(indexable);
Item item = indexable;
return (item[new ID(pass the checkbox field id here)] == "1") ? true:
- Patch the above custom crawler to the config as shown below
- Build the solution and publish to the server. Check the checkbox on whichever item you want to exclude/remove from search.
- Once publish is done, rebuild the target index from control panel and you are done.
Note: There is a method in the above CustomItemCrawler , the method name is
this is to delete the existing items/pages from the index.
I hope this post will help some of you.
Happy Coding !!!