-
Notifications
You must be signed in to change notification settings - Fork 7
Example Indexing
Hendy Racher edited this page Apr 14, 2019
·
2 revisions
The index setters would typically be set in an Umbraco startup event (but they can be changed at any-time). Eg.
public class ConfigureIndexing : ApplicationEventHandler
{
/// <summary>
/// Umbraco has started event
/// </summary>
protected override void ApplicationStarted(
UmbracoApplicationBase umbracoApplication,
ApplicationContext applicationContext)
{
// Eg. prevent hooking into any Examine indexers (only Look indexers will be used)
LookConfiguration.ExamineIndexers = null;
// Eg. index dates for news articles differently
LookConfiguration.DefaultDateIndexer = indexingContext => {
if (indexingContext.Item.DocumentTypeAlias == "newsArticle")
{
return indexingItem.GetPropertyValue<DateTime>("releaseDate");
}
return indexingContext.Item.UpdateDate;
};
// Eg. configure indexing for a specific indexer
LookConfiguration.IndexerConfiguration["MapIndexer"] = new IndexerConfiguration()
{
// only index content
ItemTypes = new[] { ItemType.Content },
// only index specific aliases
Aliases = new[] { "thing" },
// set location indexer
LocationIndexer = indexingContext => {
// eg. using Terratype
var terratype = indexingContext.Item.GetPropertyValue<Terratype.Models.Model>("location");
var terratypeLatLng = terratype.Position.ToWgs84();
return new Location(terratypeLatLng.Latitude, terratypeLatLng.Longitude);
}
};
}
}