如何对精确,语音和模糊查询赋予不同的权重? [英] How to give different weights to exact, phonetic and fuzzy queries?

查看:74
本文介绍了如何对精确,语音和模糊查询赋予不同的权重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我签出了答案,但不能解决问题。

Note: I checked out this answer, but could not solve the problem.

所以当前我正在使用以下查询:

So currently I am using the following query:

{
    "_source": [
        "title",
        "bench",
        "id_",
        "court",
        "date"
    ],
    "size": 15,
    "from": 0,
    "query": {
        "bool": {
            "must": {
                "multi_match": {
                    "query": "knife",
                    "fields": [
                        "title",
                        "body"

                    ],
                    "operator": "and"
                }
            },
            "should": {
                "multi_match": {
                    "query": "knife",
                    "fields": [
                        "title",
                        "body"
                    ],
                    "fuzziness" : 1,
                    "operator": "and"
                }
            }
        }
    },
    "highlight": {
        "pre_tags": [
            "<tag1>"
        ],
        "post_tags": [
            "</tag1>"
        ],
        "fields": {
            "content": {}
        },
        "fragment_size": 30
    }
}

我想要实现的是我想对准确,语音和模糊查询赋予不同的权重准确顺序>模糊>语音。我该如何实现?

What I want to achieve is that I want to give different weights to exact, phonetic and fuzy queries in the order exact > fuzzy > phonetic. How do I acheive this?

这是我的映射-(我的分析仪是Metaphone分析仪)

This is my mapping - (My analyzer is a Metaphone analyzer)

{
    "courts_2": {
        "mappings": {
            "properties": {
                "author": {
                    "type": "text",
                    "analyzer": "my_analyzer"
                },
                "bench": {
                    "type": "text",
                    "analyzer": "my_analyzer"
                },
                "citation": {
                    "type": "text"
                },
                "content": {
                    "type": "text",
                    "fields": {
                        "standard": {
                            "type": "text"
                        }
                    },
                    "analyzer": "my_analyzer"
                },
                "court": {
                    "type": "text"
                },
                "date": {
                    "type": "text"
                },
                "id_": {
                    "type": "text"
                },
                "title": {
                    "type": "text",
                    "fields": {
                        "standard": {
                            "type": "text"
                        }
                    },
                    "analyzer": "my_analyzer"
                },
                "verdict": {
                    "type": "text"
                }
            }
        }
    }
}


推荐答案

您可以在单独的子字段中为语音字段编制索引,如下所示:

You might index phonetic fields on an separate sub-field as follow :

   "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "fields": {
          "phonetic": {
            "type": "text",
            "analyzer": "my_analyzer"
          }
        }}}}

然后,您可以执行功能评分查询以具有准确的顺序>模糊>语音:

Then, you can do a Function score query to have the order exact > fuzzy > phonetic :

{
  "_source": [
    "title",
    "bench",
    "id_",
    "court",
    "date"
  ],
  "size": 15,
  "from": 0,
  "query": {
    "bool": {
      "should": [
        {
          "function_score": {
            "query": {
              "multi_match": {
                "query": "knife",
                "fields": [
                  "title",
                  "body"
                ],
                "operator": "and"
              }
            },
            "boost": 3
          }
        },
        {
          "function_score": {
            "query": {
              "multi_match": {
                "query": "knife",
                "fields": [
                  "title",
                  "body"
                ],
                "fuzziness": 1,
                "operator": "and"
              }
            },
            "boost": 2
          }
        },
        {
          "function_score": {
            "query": {
              "multi_match": {
                "query": "knife",
                "fields": [
                  "title.phonetic",
                  "body.phonetic"
                ],
                "operator": "and"
              }
            },
            "boost": 1
          }
        }
      ]
    }
  }
}

跳e这有帮助!

这篇关于如何对精确,语音和模糊查询赋予不同的权重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆