Sitecore Search Boundaries and Computed Fields

I have 10 articles and each article element contains a checklist of contributors

enter image description here

I created a grant Contributors for grant search in the editor. But checklist values ​​are indexed as row identifiers.

enter image description here

Now on the search results page, face values ​​appear as string identifiers. I created a ComputedField to index the display name

public class Contributors : IComputedIndexField
{
    public object ComputeFieldValue(IIndexable indexable)
    {
        var item = indexable as SitecoreIndexableItem;

        if (item == null || item.Item == null) return string.Empty;

        StringBuilder ContributorsNameList = new StringBuilder();
        IIndexableDataField cField = indexable.GetFieldByName("Contributors");
        if (cField != null)
        {

            var cList = cField.Value.ToString().Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            foreach (var cId in cList)
            {

                var cItem = item.Item.Database.GetItem(new ID(cId));

                if (cItem != null)

                    ContributorsNameList.Append(cItem.Name.ToString());

            }

            return ContributorsNameList;

        }

        return null;

    }
    public string FieldName { get; set; }
    public string ReturnType { get; set; }
}

and configuration file

<?xml version="1.0" encoding="utf-8" ?>
  <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
      <contentSearch>
        <configuration>
          <defaultIndexConfiguration>
            <fields hint="raw:AddComputedIndexField">
              <field fieldName="tagsfacet" storageType="yes" indexType="untokenized">                                      Sandbox.SitecoreCustomizations.ComputedIndexFields.TagsFacet, Sandbox</field>
            </fields>
            <fields 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>          
            </fields>
          </defaultIndexConfiguration>
        </configuration>
      </contentSearch>
    </sitecore>
  </configuration>

but now getting both id and names (occurring twice) enter image description here

+4
source share
1 answer

You need to take a look at BucketConfiguration.ResolveFacetValueToFriendlyName Sitecore.Buckets.config.

<!-- 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"/>

Mark this value true and it should work.

, ComputedField .

0

All Articles