3. Extend Contact AggregatorΒΆ

When an xDB contact is changed, the aggregation process runs. The aggregation process ensures the contact is reindexed.

A component called a contact aggregator is responsible for creating the indexable contact from the xDB contact. In other words, the contact aggregator converts the xDB contact into an instance of the class you created in Extend Indexable Contact.

You must create a custom contact aggregator that uses the indexable contact class.

  1. In Visual Studio, add the following references to the project:
  • Sitecore.Analytics.Aggregation.dll
  • Sitecore.Kernel.dll
  1. Add the following class:
using Examples.DynamicsCrm.Search;
using Sitecore.Analytics.Aggregation.Pipelines.ContactProcessing;
using Sitecore.Analytics.DynamicsCrm.Aggregators;
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.Analytics.Models;
using System;
using System.Collections.Generic;

namespace Examples.DynamicsCrm.Aggregators
{
    public class ContactChangeContactAggregatorEx2 : ContactChangeContactAggregatorEx
    {
        public ContactChangeContactAggregatorEx2(string name) : base(name) { }
        protected override IEnumerable<IContactIndexable> ResolveIndexables(ContactProcessingArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            var changeEventReason = this.GetChangeEventReason(args);
            var contact = args.GetContact();
            if (contact != null)
            {
                yield return new ContactChangeIndexable(
                    new ContactIndexableEx2(contact),
                    changeEventReason);
            }
            else
            {
                yield return new ContactChangeIndexable(
                    new IndexableUniqueId<Guid>(args.ContactId.Guid),
                    changeEventReason);
            }
        }
    }
}
  1. Compile the project.
  2. Deploy Examples.DynamicsCrm.dll to your Sitecore server.