6

I created several custom tags in my TagRepository folder that work great, but when I look at them in a bucket they display as GUIDs. After some research, I implemented a computed index field that displays the tags as their actual text.

However, the problem I am running into is the fact that the computed index field delimits spaces as separate tags (for example "Evening MBA" gets rendered as "Evening" and "MBA" separately).

Supposedly a Lucene analyzer should be able to fix this but it doesn't seem to work and I'm not seeing any relevant errors in my Sitecore logs.

My included config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <indexConfigurations>
        <defaultLuceneIndexConfiguration>
          <fields hint="raw:AddComputedIndexField">
            <field fieldName="tagsfacet" storageType="yes" indexType="untokenized" returnType="string">WSB.CMS.Utilities.ComputedIndexFields, WSB.CMS.Utilities</field>
          </fields>
          <fieldMap>
            <fieldNames hint="raw:AddFieldByFieldName">
              <field fieldName="tagsfacet" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <Analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
              </field>
            </fieldNames>
          </fieldMap>
        </defaultLuceneIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>

My Computed Index Field:

class ComputedIndexFields : IComputedIndexField
    {
        public string FieldName { get; set; }
        public string ReturnType { get; set; }

        private static readonly ID Semantics = new ID("{A14F1B0C-4384-49EC-8790-28A440F3670C}");

        public object ComputeFieldValue(IIndexable indexable)
        {
            var indexableItem = indexable as SitecoreIndexableItem;         

            return indexableItem == null ? null : indexableItem.Item.GetMultiListValues(Semantics).Select(tag => tag.DisplayName).ToList();
        }
    }

    public static class HelperMethods
    {
        public static IEnumerable<Item> GetMultiListValues(this Item item, ID fieldId)
        {
            return (new MultilistField(item.Fields[fieldId])).GetItems();
        }
    }

2 Answers 2

6

Your field is configured TOKENIZED, change it to UNTOKENIZED so that the values are not split when stored in the index.

<field fieldName="tagsfacet" indexType="UNTOKENIZED" ...>
  ....
1
  • Wow that was simple and worked like a charm! Thanks so much!
    – Fenoec
    Commented Dec 9, 2016 at 20:32
2

Assuming that your original issue was the fact that your facet was displayed as guid instead of a more readable name, I might have an answer to that problem instead of your question. There is a setting in Sitecore called ResolveFacetValueToFriendlyName which is false by default, but enabling it tells Sitecore to try to resolve the guids in facets:

<!--
 RESOLVE FACET VALUE TO FRIENDLY NAME
   If you are storing a field in the index that is being faceted on, it may be stored as an ID. This Setting
   when set to true, will try and resolve this to the friendly item name instead. 

   USAGE: In an environment with huge amounts of items (e.g. 1 Million), this will not scale properly.           

-->
<setting name="BucketConfiguration.ResolveFacetValueToFriendlyName" value="false" patch:source="Sitecore.Buckets.config"/>

A good explanation with screenshots can be found here: http://techitpro.com/uncategorized/sitecore-faceting-list-and-link-fields/

Your Answer

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

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