【问题标题】:Sitecore 9 Indexing : Solr Pattern Tokenizer not WorkingSitecore 9 索引:Solr Pattern Tokenizer 不工作
【发布时间】:2018-09-24 02:50:29
【问题描述】:

我是这个组合 sitecore 和 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"/>

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

谢谢

【问题讨论】:

    标签: solr sitecore


    【解决方案1】:

    不知道我是否在这里得到了完整的图片。也许您的方法是完全有效的,但我认为我以前从未见过这种方法。您可以重用 *_sm(多值字符串)并在 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; }
    }
    

    【讨论】:

    • 是的,你的方法是正确的..我已经这样做了..我喜欢上面,因为我需要检查标记器是否工作..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    相关资源
    最近更新 更多