ace*_*ita 3 solr sitecore facet faceted-search
有没有人有使用 SOLR 时的 sitecore 索引配置示例,用于关键字标记器?我正在尝试对具有多字串的字段进行分面,但当前返回的分面正在拆分字段中的单词并返回分面。
例如。我有一个带有州字段的项目,我正在尝试在州字段上进行分面 - 它具有像新罕布什尔州、南达科他州这样的值。但在结果中,我得到了
Name = New、Aggregate = xx
Name = Hampshire、Aggregate = xx
Name = South、Aggregate = xx
Name = Dakota、Aggregate = xx 的方面值
任何人都可以帮助我进行正确的配置来改变它吗?
这是我目前的配置:
<index id="site_search_web_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
<param desc="name">$(id)</param>
<param desc="core">site_search_web</param>
<param desc="propertyStore" ref="contentSearch/databasePropertyStore" param1="$(id)" />
<strategies hint="list:AddStrategy">
<strategy ref="contentSearch/indexUpdateStrategies/onPublishEndAsync" />
</strategies>
<locations hint="list:AddCrawler">
<crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
<Database>web</Database>
<Root>/sitecore/content/Home</Root>
</crawler>
</locations>
</index>
Run Code Online (Sandbox Code Playgroud)
您可以通过以下解决方案之一来实现这一点:
解决方案1
您可以创建一个返回构面值的计算字段,并将计算字段类型设置为“字符串”以避免标记化。您的计算字段应如下所示:
public class TitleComputedField : IComputedIndexField
{
public object ComputeFieldValue(IIndexable indexable)
{
if (indexable == null) throw new ArgumentNullException("indexable");
var scIndexable = indexable as SitecoreIndexableItem;
if (scIndexable == null)
{
Log.Warn(
this + " : unsupported IIndexable type : " + indexable.GetType(), this);
return false;
}
var item = (Item)scIndexable;
if (item == null)
{
Log.Warn(
this + " : unsupported SitecoreIndexableItem type : " + scIndexable.GetType(), this);
return false;
}
if (String.Compare(item.Database.Name, "core", StringComparison.OrdinalIgnoreCase) == 0)
{
return false;
}
return = item.Fields["Title"];
}
public string FieldName { get; set; }
public string ReturnType { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并在 Sitecore.ContentSearch.Solr.Indexes.config 中配置计算字段如下:
<fields hint="raw:AddComputedIndexField">
...
<field fieldName="plaintitle" returnType="string">YourNamespace.TitleComputedField, YourAssembly</field>
</fields>
Run Code Online (Sandbox Code Playgroud)
最后,如果您在“plaintitle”字段上进行切面,您应该会得到预期的结果。
解决方案2
您可以通过更新 solr schema.xml 在索引级别创建字段,如下所示:
在 solr 中创建一个字符串类型的新字段
<fields>
...
<field name="plaintitle" type="string" indexed="true" stored="true" />
</fields>
Run Code Online (Sandbox Code Playgroud)
然后创建一个“copyfield”将原始字段复制到新字段中
<copyField source="title_t" dest="plaintitle" />
Run Code Online (Sandbox Code Playgroud)
在这两种解决方案中,您都可以使用以下代码对新字段进行切面:
query.FacetOn(i => i["plaintitle"]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1485 次 |
| 最近记录: |