0

Sitecore 8.2 Update 4 with Lucene search on a local single instance Sitecore site: I have created a Custom Contact facet and I can see it is being saved to MongoDB.

I want to add it to the Analytics db so I can use it in the ListManager and so followed this document.

Using Luke to look at the index, I don't see the new fields and no errors in the log or Crawling log.

My config includes

<pipelines>
.....
<contactindexable.loadfields patch:source="Sitecore.ContentSearch.Analytics.config">
    <processor type="Sitecore.Foundation.Indexing.Pipelines.IndexCustomFacet, Sitecore.Foundation.Indexing"/>
</contactindexable.loadfields>

</pipelines>

When I put a breakpoint in IndexCustomFacet, it is never being hit! I can see all the expected config when I go to showconfig.aspx

<field type="System.String" fieldName="contact.Brand" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider"/>
2
  • have you seen this? sitecore.stackexchange.com/a/8832/88
    – josedbaez
    Dec 7, 2017 at 17:47
  • Follow-Up Questions: 1) What version of Sitecore? 2) What version and type of Search mechanism? (Solr? Lucene? Something else?) 3) Is this a single instance Sitecore site? Or distributed processing server? 4) Is Processing running correctly? (any errors in the log)?
    – Pete Navarra
    Dec 8, 2017 at 0:42

2 Answers 2

1

I added a custom field in this open source project I wrote. https://github.com/buildabonfire/Bonfire-Company-Personalization

Get the data

First you need a pipeline to pull the facet from the contact facet in xDB.

using System.Collections.Generic;
using System.Linq;
using Bonfire.Feature.Kickfire.Analytics.Interfaces.Entries;
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.Analytics.Pipelines.ContactIndexableLoadFields;
using Sitecore.Diagnostics;

namespace Bonfire.Feature.Kickfire.Analytics.Pipelines.CompanyIndexableLoadFields
{
    class LoadFields : ContactIndexableLoadFieldsProcessor
    {
        protected override IEnumerable<IIndexableDataField> GetFields(ContactIndexableLoadFieldsPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            var contact = args.Contact;
            Assert.IsNotNull(contact, "contact");

            //Log.Info("Starting company field aggregator",this);
            var list = new List<IIndexableDataField>();

            var value = contact.Facets.FirstOrDefault(kvp => kvp.Value is ICustomerLookup).Value;

            if (value != null)
            {
                var companyInfo = (ICustomerLookup) value;

                list = new List<IIndexableDataField>
                {
                    new IndexableDataField<string>("contact.company", companyInfo.name)
                };
            }

            return list;
        }
    }
}

Pipeline

Then patch in this config to add the code above to the ontactindexable.loadfields pipeline and then the config to add the field. Be sure to notice that the field name contact.company is both in the pipeline and the config.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <contactindexable.loadfields>
        <processor type="Bonfire.Feature.Kickfire.Analytics.Pipelines.CompanyIndexableLoadFields.LoadFields, Bonfire.Feature.Kickfire.Analytics" />
      </contactindexable.loadfields>
    </pipelines>
    <contentSearch>
      <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
        <indexes hint="list:AddIndex">
          <index id="sitecore_analytics_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
            <configuration ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration">
              <fieldMap ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/fieldMap">
                <fieldNames hint="raw:AddFieldByFieldName">
                  <field fieldName="contact.company" storageType="YES" indexType="TOKENIZED" vectorType="WITH_POSITIONS_OFFSETS" boost="1f" emptyString="_EMPTY_" nullValue="_NULL_" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                    <Analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
                  </field>
                </fieldNames>
              </fieldMap>
            </configuration>
          </index>
        </indexes>
      </configuration>
    </contentSearch>
  </sitecore>
</configuration>
0

If you added new custom contact facet to Sitecore Analytics index you will see your field in index only for new contacts, which was created after added your facet.

If you want to update your existing contacts, you need to rebuild sitecore_analytics_index. How you can do it you can find there:

Rebuilding the Sitecore Analytics Index

How to rebuild the analytics index without rebuilding the entire reporting database?

2
  • I will try that but it doesn't seem to work for new contacts. I can see them in MongoDB but not the index
    – Steve Ward
    Dec 7, 2017 at 21:24
  • I'm thinking you have either missed a step or left a configuration out. I would need to see your solution and changes to verify that something wasn't left out. Not saying I believe you did something wrong. I doubled checked and followed the guide from Sitecore (that I linked in the other question) and ensured that it was working as expected. If there is still an issue then, questions to ask would be... is the patch file that you put in for the loadfield pipeline loading in ShowConfig properly.
    – Pete Navarra
    Dec 8, 2017 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.