Function_score在布尔查询中使用score_mode作为max,但工作方式类似sum



我正在使用function_score,这样我就可以使用它的score_mode作为我正在使用的布尔查询的最大分数。实际上,我在里面有两个布尔查询。如果现在我希望文档的分数是两个查询中的最大分数,我的代码如下所示,但当我传递一个字符串来匹配这两个查询时,分数将被添加,而不是取最大值。有人能告诉我吗我怎样才能做到这一点。

"function_score": {
      "boost_mode": "max",
      "score_mode": "max",
      "query": {
        bool: {
          "disable_coord": true,
          "should": [
            {
              bool: {
                "disable_coord": true,
                "must": [
                  {
                    "constant_score": { // here i am using this because to remove tf/idf factors from my scoring
                      boost: 1.04,
                      "query": {
                        query_string: {
                          query: location_search,
                          fields: ['places_city.city'],
          //               boost: 1.04
                        }
                      }
                    }
                  }
                ]
              }
            },
            {
              "constant_score": { // here i am using this because to remove tf/idf factors from my scoring
              boost: 1,
                "query": {
                  "fuzzy_like_this" : {
                    "fields" : ["places_city.city"],
                    "like_text" : "bangaloremn",
                    "prefix_length": 3,
                    "fuzziness": 2
                  }
                }
              }
            }
         ], "minimum_should_match": 1
       }
     }
  }    

Yes布尔查询通过设计获取一个和。如果您想要两个查询的最大得分,您应该查看dismax查询。Dismax旨在挑选一个"赢家"。

粗略地说,这看起来像

{"query":
    "dismax": {
        "queries": [
             { /* your first constant_score query above */},
             {/* your second constant_score query from above */}
        ]
    }
}

不幸的是,函数分数查询并没有一种很好的方法一次处理多个文本查询。请参阅此问题。如果你想用多个查询的分数做任何复杂的数学运算,Solr在这方面实际上有更大的灵活性。

最新更新