Created
August 19, 2013 12:14
-
-
Save adoprog/6268477 to your computer and use it in GitHub Desktop.
Exclude Sitecore templates from index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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