Index custom contact facets
Index your custom contact facets during aggregation.
You can create custom contact facets to include information that your organization wants to track, for example, addresses, country, or email addresses. To index these custom contact facets during the aggregation process, you must extend the contactindexable.loadfields pipeline.
The contactindexable.loadfields pipeline is used by the Sitecore.ContentSearch.Analytics.Models.ContactIndexable field type to load fields that are available for indexing. Custom processors in the contactindexable.loadfields pipeline must inherit from the Sitecore.ContentSearch.Analytics.Pipelines.ContactIndexableLoadFields.ContactIndexableLoadFieldsProcessor base class.
Depending on whether you use Lucene or Solr, you must configure the Sitecore.ContentSearch.Lucene.Index.Analytics.config or Sitecore.ContentSearch.Solr.Index.Analytics.config files to define which indexable fields are added to the appropriate indexes.
Note
This functionality is only available from Sitecore 8.1 update 3 and later.
To index a custom contact facet:
Implement a custom processor that extends the
contactindexable.loadfieldspipeline to add data from the custom facet to the collection of contact indexable fields:using System.Collections.Generic; using Sitecore.ContentSearch; using Sitecore.ContentSearch.Analytics.Pipelines.ContactIndexableLoadFields; using Sitecore.Diagnostics; namespace Sitecore.IndexingCustomFacets { public class LoadFields : ContactIndexableLoadFieldsProcessor { protected override IEnumerable<IIndexableDataField> GetFields(ContactIndexableLoadFieldsPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); var contact = args.Contact; Assert.IsNotNull(contact, "contact"); var fields = new List<IIndexableDataField>(); var customFacet = contact.GetFacet<ICustomContactFacet>("CustomContactFacetName"); if (customFacet != null) { fields.Add(new IndexableDataField<bool>("contact.CustomFieldName", customFacet.CustomField)); } return fields; } } }In the
\App_Config\Includefolder, create a new configuration include file that adds the new processor to thecontacindexable.loadfieldspipeline:<?xml version="1.0" encoding="utf-8" ?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" <sitecore> <pipelines> <contactindexable.loadfields> <processor type="Sitecore.IndexingCustomFacets.LoadFields, Sitecore.IndexingCustomFacets" /> </contactindexable.loadfields> </pipelines> </sitecore> </configuration>Copy the new configuration file to the
App_Config\Includefolder of your website.Configure the analytics index to store the new field in the index.
If you use Lucene, create the new configuration include file to add the new field under the <
fieldNames hint="raw:AddFieldByFieldName"> node defined in in theSitecore.ContentSearch.Lucene.Index.Analytics.configfile.For example:
<?xml version="1.0" encoding="utf-8" ?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" <sitecore> <contentSearch> <configuration> <indexes> <index id="sitecore_analytics_index"> <configuration> <fieldMap> <fieldNames> <field fieldName="contact.CustomFieldName" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.Boolean" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" /> </fieldNames> </fieldMap> </configuration> </index> </indexes> </configuration> </contentSearch> </sitecore> </configuration>If you use Solr, create the new configuration include file to add the new field under the
<fieldNames hint="raw:AddFieldByFieldName">node defined in theSitecore.ContentSearch.Solr.Index.Analytics.configfile.For example:
<?xml version="1.0" encoding="utf-8" ?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" <sitecore> <contentSearch> <configuration> <indexes> <index id="sitecore_analytics_index"> <configuration> <fieldMap> <fieldNames> <field fieldName="contact.CustomFieldName" returnType="bool" /> </fieldNames> </fieldMap> </configuration> </index> </indexes> </configuration> </contentSearch> </sitecore> </configuration>