public async Task BuildIndexAsync(BuildIndexContext context) { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); if (contentTypeDefinition == null) { return; } foreach (var contentTypePartDefinition in contentTypeDefinition.Parts) { var partName = contentTypePartDefinition.Name; var partTypeName = contentTypePartDefinition.PartDefinition.Name; var partType = _contentPartFactory.GetContentPartType(partTypeName) ?? typeof(ContentPart); var part = context.ContentItem.Get(partType, partName) as ContentPart; var typePartIndexSettings = contentTypePartDefinition.GetSettings <ContentIndexSettings>(); // Skip this part if it's not included in the index and it's not the default type part if (partName != partTypeName && !typePartIndexSettings.Included) { continue; } await _partIndexHandlers.InvokeAsync(partIndexHandler => partIndexHandler.BuildIndexAsync(part, contentTypePartDefinition, context, typePartIndexSettings), Logger); foreach (var contentPartFieldDefinition in contentTypePartDefinition.PartDefinition.Fields) { var partFieldIndexSettings = contentPartFieldDefinition.GetSettings <ContentIndexSettings>(); if (!partFieldIndexSettings.Included) { continue; } await _fieldIndexHandlers.InvokeAsync(_fieldIndexHandler => _fieldIndexHandler.BuildIndexAsync(part, contentTypePartDefinition, contentPartFieldDefinition, context, partFieldIndexSettings), Logger); } } return; }
Task IContentPartIndexHandler.BuildIndexAsync(ContentPart contentPart, ContentTypePartDefinition typePartDefinition, BuildIndexContext context, ContentIndexSettings settings) { var part = contentPart as TPart; if (part == null) { return(Task.CompletedTask); } var buildPartIndexContext = new BuildPartIndexContext(context.DocumentIndex, context.ContentItem, typePartDefinition.Name, typePartDefinition, settings); return(BuildIndexAsync(part, buildPartIndexContext)); }
Task IContentFieldIndexHandler.BuildIndexAsync(ContentPart contentPart, ContentTypePartDefinition typePartDefinition, ContentPartFieldDefinition partFieldDefinition, BuildIndexContext context, ContentIndexSettings settings) { if (!string.Equals(typeof(TField).Name, partFieldDefinition.FieldDefinition.Name) && !string.Equals(nameof(ContentField), partFieldDefinition.FieldDefinition.Name)) { return(Task.CompletedTask); } var field = contentPart.Get <TField>(partFieldDefinition.Name); if (field != null) { var buildFieldIndexContext = new BuildFieldIndexContext(context.DocumentIndex, context.ContentItem, $"{typePartDefinition.Name}.{partFieldDefinition.Name}", contentPart, typePartDefinition, partFieldDefinition, settings); return(BuildIndexAsync(field, buildFieldIndexContext)); } return(Task.CompletedTask); }