【发布时间】: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>
【问题讨论】:
-
您是否尝试在代码中放置断点或添加
Log.Info来调试它返回的内容?您不需要在AddComputedField和AddFieldByFieldName部分中添加tagsFacet。AddComputedField应该足够了。您还检查了卢克中tagsFacet字段的值是多少?我只看到contributors字段中的屏幕截图。
标签: asp.net-mvc sitecore sitecore8 sitecore-lucene