Also, "multiple vs single index" question is a rather hot topic, see the following discussion, for example: http://stackoverflow.com/questions/2746568/multiple-or-single-index-in-lucene
When you don't want to index just everything, it would be great to be able to choose which templates you want to index and leave the rest of the data out instead of manually excluding hundreds of templates. Unfortunately, it is not supported out of the box, even though there are some unused methods / properties for "list:IncludeTemplates" functionality. But it can be achieved by customizing the LuceneIndexConfiguration class and the following trick - you can put all templates to "Exclude Templates", except the ones that are added to "Include Templates".
Step 1. Compile the following code:
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); | |
} | |
} |
Step 2. Replace Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration with %your namespace%.ExtendedIndexConfiguration in your index config.
Step 3. Configure templates you wan to index in a following way:
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
<include hint="list:IncludeTemplate"> | |
<Article>{7B14FE7B-F658-4885-AAD6-7D569BAE579B}</Article> | |
</include> |
No comments:
Post a Comment