我有10篇文章内容项,每篇文章项都有一个贡献者清单 我在编辑器中为分面搜索创建了一个贡献者方面.但是核对表值被索引为字符串id. 现在在搜索结果页面上,构面值显示为字符串ID. 我
我在编辑器中为分面搜索创建了一个贡献者方面.但是核对表值被索引为字符串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和名字(发生两次)
在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就会过时.