Skip to content

Instantly share code, notes, and snippets.

@adoprog
Created August 19, 2013 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adoprog/6268477 to your computer and use it in GitHub Desktop.
Save adoprog/6268477 to your computer and use it in GitHub Desktop.
Exclude Sitecore templates from index
public class ExtendedIndexConfiguration : LuceneIndexConfiguration
{
private bool templatesExcluded;
public void IncludeTemplate(string value)
{
Assert.ArgumentNotNull(value, "value");
Assert.IsTrue(ID.IsID(value), "Configuration: IncludeTemplate entry not a valid GUID. Field ID Value: " + value);
// First exclude all templates, if it is not yet done.
if (!this.templatesExcluded)
{
var database = Database.GetDatabase("master");
var items = database.SelectItems("fast:/sitecore/templates//*[@@templatename='Template']");
foreach (var item in items)
{
if (!DocumentOptions.IncludedTemplates.Contains(item.ID.ToString()))
{
ExcludeTemplate(item.ID.ToString());
}
}
this.templatesExcluded = true;
}
this.DocumentOptions.IndexingFilters.Remove(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment