Mike Robbins

Sitecore Developer Blog

Follow me on GitHub

Sitecore 7 Search by base templates

Quick tip, when using Sitecore 7's search API to build a general site search, you may want to return only pages rather than any other items within Sitecore. All my page items inherit from a base Item to implement page title, meta data and so on. Using linq we are able to check whether an item is based on a specific base template, to do this we need to tell Sitecore to index the base templates.

By default in Sitecore 7 indexing base templates is disabled to improve the indexing speed. This is very simple to switch on.

Inside the section within your index uncomment the line below.

 <field fieldName="_templates" storageType="yes" indexType="untokenized">Sitecore.ContentSearch.ComputedFields.AllTemplates, Sitecore.ContentSearch</field>

Rebuild your index and these base templates are now accessible in your search result class.