代码之家  ›  专栏  ›  技术社区  ›  Nariman Esmaiely Fard

当第一个字母拼写错误时,来自elasticsearch短语suggester的意外结果

  •  0
  • Nariman Esmaiely Fard  · 技术社区  · 6 年前

    我正在使用Elasticsearch短语Suggester来纠正用户的拼写错误。一切都如我所料,除非用户输入一个查询,它的第一个字母拼写错误。在这种情况下,短语suggester不返回任何内容或返回意外结果。

    我的文档和查询与 phrase suggester :

    POST test/test?refresh=true
    {"title": "noble warriors"}
    POST test/test?refresh=true
    {"title": "nobel prize"}
    
        POST test/_search
    {
      "suggest": {
        "text": "noble prize",
        "simple_phrase": {
          "phrase": {
            "field": "title.trigram",
            "size": 1,
            "gram_size": 3,
            "direct_generator": [ {
              "field": "title.trigram",
              "suggest_mode": "always"
            } ],
            "highlight": {
              "pre_tag": "<em>",
              "post_tag": "</em>"
            }
          }
        }
      }
    }
    

       {
      "_shards": ...
      "hits": ...
      "timed_out": false,
      "took": 3,
      "suggest": {
        "simple_phrase" : [
          {
            "text" : "mobel prize",
            "offset" : 0,
            "length" : 11,
            "options" : []
          }
        ]
      }
    }
    

    第4个字母拼写错误的示例:

    {
      "_shards": ...
      "hits": ...
      "timed_out": false,
      "took": 3,
      "suggest": {
        "simple_phrase" : [
          {
            "text" : "noble prize",
            "offset" : 0,
            "length" : 11,
            "options" : [ {
              "text" : "nobel prize",
              "highlighted": "<em>nobel</em> prize",
              "score" : 0.5962314
            }]
          }
        ]
      }
    }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   femtoRgon    6 年前

    更改生成器的前缀长度。

    前缀长度

    一个警告,通常将模糊匹配查询的前缀长度设置为零,会对性能产生相当大的负面影响。