加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – Sitecore搜索方面和计算字段

发布时间:2020-12-16 09:20:23 所属栏目:asp.Net 来源:网络整理
导读:我有10篇文章内容项,每篇文章项都有一个贡献者清单 我在编辑器中为分面搜索创建了一个贡献者方面.但是核对表值被索引为字符串id. 现在在搜索结果页面上,构面值显示为字符串ID. 我创建了一个ComputedField来索引显示名称 public class Contributors : IComput
我有10篇文章内容项,每篇文章项都有一个贡献者清单

enter image description here

我在编辑器中为分面搜索创建了一个贡献者方面.但是核对表值被索引为字符串id.

enter image description here

现在在搜索结果页面上,构面值显示为字符串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和名字(发生两次)

enter image description here

解决方法

你需要看看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就会过时.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读