In this article you’ll find:
Table of Contents |
---|
Goal
The purpose of this article is to show you how to exclude certain documents from being sent to Hawksearch based on some field value. 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.
Prerequisites
Info |
---|
|
Steps to excluding documents from being indexed
Override the GetDocuments method and implement your custom logic. In the following snippet we will exclude all documents which have an “EventEndDate” field name with a value that is in the past, meaning that the event has already passed.
Code Block public override IEnumerable<SubmitDocument> GetDocuments(IEnumerable<FieldMappingInfo> fieldMappings, IEnumerable<string> identifiers = null) { var documents = base.GetDocuments(fieldMappings, identifiers); documents = documents.Where(a => !a.Fields.Any(b => b.Name == "EventEndDate" && DateTime.Now > DateTime.Parse(b.Values.First()))); return documents; }
...