【问题标题】:Unexpected result from elasticsearch Phrase suggester when first letter is misspelled当第一个字母拼写错误时,来自弹性搜索短语建议器的意外结果
【发布时间】:2018-07-15 06:15:41
【问题描述】:

我正在使用 Elasticsearch Phrase 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
        }]
      }
    ]
  }
}

【问题讨论】:

    标签: elasticsearch lucene


    【解决方案1】:

    更改生成器的前缀长度。

    前缀长度

    必须匹配才能成为候选建议的最小前缀字符数。默认为 1。增加此数字可提高拼写检查性能。通常拼写错误不会出现在术语的开头。 (旧名称“prefix_len”已弃用)

    警告,通常将此类模糊匹配查询的前缀长度设置为零往往会对性能产生相当大的不利影响。

    【讨论】:

      猜你喜欢
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      相关资源
      最近更新 更多