搜索连接词的Solr索引

时间:2017-06-06 12:33:06

标签: solr lucene n-gram text-analysis

我正在努力解决两个类似的用例。

这是我索引中的示例文档:

{
        "id":"E850AC8D844010AFA76203B390DD3135",
        "brand_txt_en":"Tom Ford",
        "catch_all":["Tom Ford",
          "FT 5163",
          "Tom Ford",
          "FT 5163",
          "DARK HAVANA"],
        "model_txt_en":"FT 5163",
        "brand_txt_en_split":"Tom Ford",
        "model_txt_en_split":"FT 5163",
        "color_txt_en":"DARK HAVANA",
        "material_s":"acetato",
        "gender_s":"uomo",
        "shape_s":"Wayfarer",
        "lens_s":"cerchiata",
        "modelkey_s":"86_1_FT 5163",
        "sales_i":0,
        "brand_s":"Tom Ford",
        "model_s":"FT 5163",
        "color_s":"DARK HAVANA",
        "_version_":1569456572504997895
}

查询: brand_txt_en_split:tomford

没有结果!

字段类型是Solr的默认字段:

<fieldType name="text_en_splitting" class="solr.TextField" autoGeneratePhraseQueries="true" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_en.txt" ignoreCase="true"/>
      <filter class="solr.WordDelimiterFilterFactory" catenateNumbers="1" generateNumberParts="1" splitOnCaseChange="1" generateWordParts="1" catenateAll="0" catenateWords="1"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
      <filter class="solr.PorterStemFilterFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.SynonymFilterFactory" expand="true" ignoreCase="true" synonyms="synonyms.txt"/>
      <filter class="solr.StopFilterFactory" words="lang/stopwords_en.txt" ignoreCase="true"/>
      <filter class="solr.WordDelimiterFilterFactory" catenateNumbers="0" generateNumberParts="1" splitOnCaseChange="1" generateWordParts="1" catenateAll="0" catenateWords="0"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
      <filter class="solr.PorterStemFilterFactory"/>
    </analyzer>
  </fieldType>

我希望WordDelimiterFilterFactory能够生成&#34; tomford&#34;通过连接单词来表示令牌,但看起来它没有按预期工作。

&#39;反向&#39;用例是:

{ 
   ...  "model_txt_en_split": "The Clubmaster", ...
}

我希望在此查询后找到该文档: 分会大师

我想我应该在后一种情况下使用EdgeNGram过滤器,但实际上无法做到这一点。

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

WordDelimiterFilterFactory包含catenateWordscatenateAll。它适用于你拥有的地方:

catenateWords: (integer, default 0) If non-zero, maximal runs of word parts will be joined: "hot-spot-sensor's" -> "hotspotsensor"

catenateAll: (0/1, default 0) If non-zero, runs of word and number parts will be joined: "Zap-Master-9000" -> "ZapMaster9000"`

要删除单词之间的空格,请尝试使用以下过滤器。

<filter class="solr.PatternReplaceFilterFactory" pattern="(\s+)" replacement="" replace="all" />

添加/更新schema.xml后。重新启动服务器并重新索引数据。

您可以为您的字段名称尝试以下fieldType。

<analyzer>
  <tokenizer class="solr.KeywordTokenizerFactory"/>
  <filter class="solr.EdgeNGramFilterFactory" minGramSize="4" maxGramSize="25"/>
</analyzer>

输入字符串:"John Oliver W Clane"

要过滤的标记符:"John Oliver W Clane"

输出代币:

"John", "John ", "John O", "John Ol", "John Oli", "John Oli", "John Oliv", "John Olive", "John Oliver", "John Oliver ", "John Oliver W", "John Oliver W "
, "John Oliver W C", "John Oliver W Cl", "John Oliver W Cla", "John Oliver W Clan", "John Oliver W Clane".

您可以尝试使用其他过滤器。

<filter class="solr.NGramFilterFactory" minGramSize="4" maxGramSize="25"/>

您可以阅读有关分析器和过滤器的更多信息Solr Analyzers and Filters