In this article you’ll find:
Table of Contents |
---|
Goal
The purpose of this article is to show you how to add additional information to a document. For the purpose of this tutorial, it will be assumed that you have inherited the Hawksearch.Kentico.Xperience.CMS.Services.Indexing.Indexer class and want to extend its behavior instead of writing your own Indexer from scratch.
Prerequisite
Info |
---|
|
Steps to adding additional information to a document
Override the GetDocuments method and write out your custom logic. For example the following snippet adds a custom field called “CustomEventItemFieldName” on all Documents which have a field with a name “ContentType” which has a value of “Event”.
Code Block public override IEnumerable<SubmitDocument> GetDocuments(IEnumerable<FieldMappingInfo> fieldMappings, IEnumerable<string> identifiers = null) { var documents = base.GetDocuments(fieldMappings, identifiers); foreach (var document in documents) { if (document.Fields.Any(a => a.Name == "ContentType" && a.Values.Any(b => b == "Event"))) { document.Fields.Add(new SubmitField { Name = "CustomEventItemFieldName", Values = new List<string> { "CustomEventItemValue" } }); } } return documents; }
...