/
Kentico: Example: Exclude documents based on a column value

Kentico: Example: Exclude documents based on a column value

In this article you’ll find:

Goal

The purpose of this article is to show you how to exclude certain documents from being written to a csv file based on some database column value. For the purpose of this tutorial, it will be assumed that you have inherited the Hawksearch.Kentico.Xperience.CMS.Services.Indexing.Exporter class and want to extend its behavior instead of writing your own Exporter from scratch.

Prerequisites

Steps to excluding documents from being indexed

  1. Override the AddData method and implement your custom logic. In the following snippet we will exclude all documents which have an “EventEndDate” column name with a value that is in the past, meaning that the event has already passed.

    public override IList<DataRetrievingModel> AddData(IList<DataRetrievingModel> data) { var baseData = base.AddData(data); foreach (var baseDataModel in baseData) { if (baseDataModel.Key == "Content") //Exclude only content items. { for (int i = baseDataModel.FeedData.Count - 1; i >= 0; i--) { var columnValue = baseDataModel.FeedData[i]["EventEndDate"]; if (columnValue != null) { var columnDate = DateTime.Parse(columnValue.ToString()); if (columnDate < DateTime.Now) //Date is in the past. { baseDataModel.FeedData.RemoveAt(i); //Remove from content items. } } } } } return baseData; }
  2. That’s it. Now the exporter will exclude documents which have an event end date in the past.

Related content

Kentico: Example: Exclude documents based on a field value
Kentico: Example: Exclude documents based on a field value
More like this
Kentico: Example: Adding additional information to a document
Kentico: Example: Adding additional information to a document
More like this
Filtering results based on a condition
Filtering results based on a condition
More like this
Indexing operations
Indexing operations
More like this
Kentico: Creating your own File Exporter
Kentico: Creating your own File Exporter
More like this
Kentico: File Export overview
Kentico: File Export overview
More like this