瀏覽代碼

Java api: add missing boost support to TermsQueryBuilder

Relates to #11744
Closes #11810
javanna 10 年之前
父節點
當前提交
90a7b4868e
共有 1 個文件被更改,包括 13 次插入1 次删除
  1. 13 1
      core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java

+ 13 - 1
core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java

@@ -26,7 +26,7 @@ import java.io.IOException;
 /**
  * A filer for a field based on several terms matching on any of them.
  */
-public class TermsQueryBuilder extends QueryBuilder {
+public class TermsQueryBuilder extends QueryBuilder implements BoostableQueryBuilder<TermsQueryBuilder> {
 
     private final String name;
 
@@ -36,6 +36,8 @@ public class TermsQueryBuilder extends QueryBuilder {
 
     private String execution;
 
+    private float boost = -1;
+
     /**
      * A filer for a field based on several terms matching on any of them.
      *
@@ -131,6 +133,12 @@ public class TermsQueryBuilder extends QueryBuilder {
         return this;
     }
 
+    @Override
+    public TermsQueryBuilder boost(float boost) {
+        this.boost = boost;
+        return this;
+    }
+
     @Override
     public void doXContent(XContentBuilder builder, Params params) throws IOException {
         builder.startObject(TermsQueryParser.NAME);
@@ -140,6 +148,10 @@ public class TermsQueryBuilder extends QueryBuilder {
             builder.field("execution", execution);
         }
 
+        if (boost != -1) {
+            builder.field("boost", boost);
+        }
+
         if (queryName != null) {
             builder.field("_name", queryName);
         }