有没有办法为查询设置分数范围(或最大分数)

时间:2017-07-07 08:02:06

标签: ruby-on-rails elasticsearch elasticsearch-ruby

我有一个非常简单的查询:

TextView textView = (TextView) findViewById(R.id.textView8);
int numberOfColumnsEntered = 0;
public void getNumber(View view) {
   // get number logic then
   textView.setText("Enter Column No. "+(numberOfColumnsEntered+1)+" in which your letters appear");
}

public void buttondone(View view) {
    EditText op  = (EditText) findViewById(R.id.operator2);
    String num = op.getText().toString();
    getlist[numberofColumnsEntered] = Integer.parseInt(num);
    numberofColumnsEntered++;
    textView.setText("Enter Column No. "+(numberOfColumnsEntered+1)+" in which your letters appear");
    if(numberofColumnsEntered == x) {
    Toast.makeText(getApplicationContext(), "Inserted", Toast.LENGTH_LONG).show();
    }
}

使用constant_score组成了几个(大约10个)其他查询。问题是,在特定条款下,我的查询得分太高,无法取消所有其他查询结果。

以下是解释的一部分:

match: {
  field => {
    boost: 4,
    query: term,
    fuzziness: 'AUTO',
  }
}

你有没有看到,由于以色列国防军的得分为11.38。 我的其他查询(分数在1到3之间)完全没用。

我的问题是:

如何为查询设置最高可能分数?

或者,更好的是,我可以为查询设置一个分数范围吗?

我想避免对此字段进行constant_score查询,我需要一些TF / IDF并为此字段评分,但不是那么强。

我试过了:

"details" => [
[0] {
      "value" => 63.656006,
"description" => "sum of:",
    "details" => [
    [0] {
              "value" => 63.656006,
        "description" => "weight(title.de:kandinsky in 1694239) [PerFieldSimilarity], result of:",
            "details" => [
            [0] {
                      "value" => 63.656006,
                "description" => "score(doc=1694239,freq=1.0 = termFreq=1.0\n), product of:",
                    "details" => [
                    [0] {
                              "value" => 4.0,
                        "description" => "boost",
                            "details" => []
                    },
                    [1] {
                              "value" => 11.3820715,
                        "description" => "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
[...]

它更好但在某些情况下它仍然可以获得非常高的分数。

2 个答案:

答案 0 :(得分:1)

最后,我在1 - (1/x)中使用了script_score函数中的函数分数和脚本分数

GET _search
{
  "query": {
    "function_score": {
      "query": {
        "match": {
          "postgresql.log.message": "alter"
        }
      },
      "script_score" : {
                "script" : {
                    "params": {
                        "max_score": 5
                    },
                    "source": "params.max_score * (1 - 1 / _score)" 
                }
            }
    }
  }
}

这样,我的分数将在0到近5之间(max_score)。

您可以使用单词alter(分数3.9150627)或alter table pgbench_branches add primary key (bid)(分数4.8539715)来here

您可以调整1 - (1/x)函数以更快地接近渐近线。

答案 1 :(得分:0)

您是否尝试使用功能评分查询?  这是相同的链接 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html