Sitecore поиск фасетов и вычисляемых полей
У меня есть 10 элементов содержимого статьи, и каждый элемент статьи имеет контрольный список авторов
Я создал фасет Contributors для фасетного поиска в редакторе. Но значения контрольного списка индексируются как строковые идентификаторы.
Теперь на странице результатов поиска значения фасетов отображаются как строковые идентификаторы. Я создал 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>
но теперь получаю оба идентификатора и имена (встречается дважды)
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 должен стать устаревшим.