Keith
Keith

Reputation: 4147

excluding templates from search in sitecore

I can't seem to get this to work. I started with how to use Linq to get a sitecore field but have stalled. I'm trying to exclude certain pages/templates. Here is what I have:

var query = PredicateBuilder.True<SearchResultItem>();
query = query.And(i => i.Paths.Contains(homeItem.ID));
query = query.And(i => i.Content.Contains(searchTerm));
query = query.And(i => i.TemplateName != "MenuFolder");
query = query.And(i => i["Template"] != "/sitecore/templates/Common/Folder");

The last one, with the path "/sitecore/templates/Common/Folder", I can't get to work. I want to make sure that when a search is performed that none of the folders come up in the search. I've used variations of Path, Paths, TemplateName, TemplateID, but I can't seem to make it work.

Upvotes: 1

Views: 861

Answers (1)

Hishaam Namooya
Hishaam Namooya

Reputation: 1081

Try to do the following:

var query = PredicateBuilder.True<SearchResultItem>();
query = query.And(i => i.Paths.Contains(homeItem.ID));
query = query.And(i => i.Content.Contains(searchTerm));
query = query.And(i => i.TemplateName != "MenuFolder");
query = query.And(i => i.TemplateId != Sitecore.TemplateIDs.Folder);

The Sitecore.TemplateIDs.Folder is the ID of the folder in the path /sitecore/templates/Common/Folder and its ID is {A87A00B1-E6DB-45AB-8B54-636FEC3B5523}

Thanks

Upvotes: 2

Related Questions