首页 > 解决方案 > 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"/>

知道我上面的配置有什么问题吗?

谢谢

标签: solrsitecore

解决方案


不知道我是否在这里得到了完整的图片。也许您的方法是完全有效的,但我认为我以前从未见过这种方法。*_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; }
}

推荐阅读