gpt4 book ai didi

solr - 使用 SOLR 对短语进行 Sitecore 分面

转载 作者:行者123 更新时间:2023-12-01 12:37:43 25 4
gpt4 key购买 nike

有人在使用 SOLR 时为关键字分词器提供 sitecore 索引配置示例吗?我正在尝试在具有多词字符串的字段上进行分面,但当前返回的分面正在拆分字段中的单词并返回分面。

例如。我有一个带有状态字段的项目,我正在尝试在状态字段上进行分面 - 它具有像新罕布什尔州,南达科他州这样的值。但在结果中,我得到了

的构面值名称 = 新,聚合 = xx
名称 = 汉普郡,聚合 = xx
名称 = 南,聚合 = xx
姓名 = Dakota,汇总 = 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>

最佳答案

您可以通过以下解决方案之一实现此目的:

解决方案 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; }
}

并在 Sitecore.ContentSearch.Solr.Indexes.config 中配置计算字段,如下所示:

      <fields hint="raw:AddComputedIndexField">
...
<field fieldName="plaintitle" returnType="string">YourNamespace.TitleComputedField, YourAssembly</field>
</fields>

最后,如果您在“plaintitle”字段上分面,您应该会得到预期的结果。

解决方案 2

您可以通过更新 solr schema.xml 来创建索引级别的字段,如下所示:

在solr中新建一个字符串类型的字段

<fields>
...
<field name="plaintitle" type="string" indexed="true" stored="true" />
</fields>

然后创建一个“复制域”,将原来的域复制到新的域中

<copyField source="title_t" dest="plaintitle" />

在这两种解决方案中,您都可以使用以下代码对新字段进行分面:

query.FacetOn(i => i["plaintitle"]);

关于solr - 使用 SOLR 对短语进行 Sitecore 分面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28116532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com