solr - Sitecore 9 索引:Solr Pattern Tokenizer 不工作
问题描述
我是这个组合 sitecore 和 solr 东西的新手。我对不工作的模式标记器有一点问题。我正在关注这个文档
Solr: https ://lucene.apache.org/solr/guide/6_6/tokenizers.html#Tokenizers-RegularExpressionPatternTokenizer )
Sitecore 9 Solr: https ://doc.sitecore.net/sitecore_experience_platform/setting_up_and_maintaining/search_and_indexing/using_solr_field_name_resolution
当我进行索引时,我的字段值是:a,b,c 我希望在 solr 上它将是 ["a","b","c"] 但它包含 ["a,b,c"]
这是我的 Sitecore 配置
<fieldMap>
<typeMatches hint="raw:AddTypeMatch">
<typeMatch type="System.Collections.Generic.List`1[System.String]" typeName="commaDelimitedCollection" fieldNameFormat="{0}_cd"
multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider"/>
</typeMatches>
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="Keywords" returnType="commaDelimitedCollection"/>
</fieldNames>
</fieldMap>
这是我的 Solr 架构
<fieldType name="commaDelimited" class="solr.TextField" multiValued="true">
<analyzer>
<tokenizer class="solr.PatternTokenizerFactory" pattern="\s*,\s*"/>
</analyzer>
</fieldType>
<dynamicField name="*_cd" type="commaDelimited" multiValued="true" indexed="true" stored="true"/>
知道我上面的配置有什么问题吗?
谢谢
解决方案
不知道我是否在这里得到了完整的图片。也许您的方法是完全有效的,但我认为我以前从未见过这种方法。*_sm
您可以重用(multiValued string) 并在 Sitecore 端的索引时间执行字符串拆分,而不是定义新类型。通常,您不需要比 sitecore 提供的字段类型更多的字段类型,并且通常更容易维护 VS 解决方案中的所有代码,而不是依赖于额外的 Solr 配置。(不过,在 Sitecore 9 中,您可以从控制面板部署 Solr 托管模式。)
一个简单的计算域字段可以如下所示:
<fields hint="raw:AddComputedIndexField">
<field fieldName="keywords" returnType="stringCollection">
Your.Name.Space.YourComputedFieldClass, YourAssembly
</field>
</fields>
一个类的实现可能看起来像这样:
public class YourComputedFieldClass : IComputedIndexField
{
public object ComputeFieldValue(IIndexable indexable)
{
var item = indexable as SitecoreIndexableItem;
var fieldValue = item?.Item?["Keywords"]
if (string.IsNullOrWhitespace(fieldValue)) {
return null;
}
return fieldValue.Split(',');
}
public string FieldName { get; set; }
public string ReturnType { get; set; }
}
推荐阅读
- python - 如果表格有不同的选项卡,如何将 html 表格放入 python?
- c++ - 为什么 C++ 中的字符串文字 (char*) 必须是常量?
- node.js - 部署 docker 镜像
- bash - 以root用户身份在脚本bash_aliases中创建别名的问题
- lua - 使用键聚焦时 TextBox 值会发生变化
- python-3.x - 如何从 Python 中的路径获取没有路径的文件名?
- ibm-midrange - AS400 - IBM 批处理作业问题
- python - 在 Python 中对存储在 numpy 数组中的文件夹标签进行编码
- vb.net - VB.NET 和 XmlElement() 如何从 API 调用中获取元素的值?
- python - 将测试标记为从 pytest 中的夹具内部通过