Skip to content

Commit afab198

Browse files
committed
Add Query.unscore() to remove scores from a QueryBuilder, use it from tests
1 parent 967d0fe commit afab198

File tree

4 files changed

+76
-62
lines changed

4 files changed

+76
-62
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/querydsl/query/Query.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
* </p>
2929
*/
3030
public abstract class Query {
31+
32+
// Boosting used to remove scoring from queries that don't contribute to it
33+
public static final float NO_SCORE_BOOST = 0.0f;
34+
3135
private final Source source;
3236

3337
protected Query(Source source) {
@@ -51,7 +55,7 @@ public Source source() {
5155
public final QueryBuilder toQueryBuilder() {
5256
QueryBuilder builder = asBuilder();
5357
if (scorable() == false) {
54-
builder.boost(0.0f);
58+
builder = unscore(builder);
5559
}
5660
return builder;
5761
}
@@ -103,4 +107,11 @@ public Query negate(Source source) {
103107
public boolean scorable() {
104108
return false;
105109
}
110+
111+
/**
112+
* Removes score from a query builder, so score is not affected by the query
113+
*/
114+
public static QueryBuilder unscore(QueryBuilder builder) {
115+
return builder.boost(NO_SCORE_BOOST);
116+
}
106117
}

0 commit comments

Comments
 (0)