【问题标题】:Sitecore search facets and Computed FieldsSitecore 搜索方面和计算字段
【发布时间】:2016-07-08 10:07:20
【问题描述】:

我有 10 个文章内容项,每个文章项都有一个贡献者清单

我在编辑器中创建了一个 Contributors Facet 用于分面搜索。但是清单值被索引为字符串 id。

现在在搜索结果页面上,构面值显示为字符串 id。 我创建了一个 ComputedField 来索引显示名称

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; }
}

和配置文件

<?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>

但现在同时获取 id 和名称(出现两次)

【问题讨论】:

  • 您是否尝试在代码中放置断点或添加Log.Info 来调试它返回的内容?您不需要在AddComputedFieldAddFieldByFieldName 部分中添加tagsFacetAddComputedField 应该足够了。您还检查了卢克中tagsFacet 字段的值是多少?我只看到 contributors 字段中的屏幕截图。

标签: asp.net-mvc sitecore sitecore8 sitecore-lucene


【解决方案1】:

你需要看看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"/>

将此值修补为 true,它应该可以工作。

这样你的 ComputedField 应该会过时。

【讨论】:

  • 现在我可以索引名称,但它同时出现两次 id 和名称。
  • 我已经编辑了计算域类。请评价一下。
  • 检查这个:techitpro.com/sitecore-faceting-list-and-link-fields 当使用我向你展示的设置时,你不需要计算域来做你想做的事情。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多