Skip to content

Commit ecba81a

Browse files
committed
Merge pull request #12072 from cbuescher/feature/query-refactoring-fixemptyqb
Query Refactoring: Make EmptyQueryBuilder implement QueryBuilder directly
2 parents 6c02301 + 51a27ab commit ecba81a

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

core/src/main/java/org/elasticsearch/index/query/EmptyQueryBuilder.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
package org.elasticsearch.index.query;
2121

2222
import org.apache.lucene.search.Query;
23+
import org.elasticsearch.action.support.ToXContentToBytes;
2324
import org.elasticsearch.common.io.stream.StreamInput;
2425
import org.elasticsearch.common.io.stream.StreamOutput;
2526
import org.elasticsearch.common.xcontent.XContentBuilder;
27+
import org.elasticsearch.common.xcontent.XContentType;
2628

2729
import java.io.IOException;
2830

@@ -35,15 +37,16 @@
3537
* intended to be used internally as a stand-in for nested queries that are left empty and should
3638
* be ignored upstream.
3739
*/
38-
public class EmptyQueryBuilder extends AbstractQueryBuilder<EmptyQueryBuilder> {
40+
public class EmptyQueryBuilder extends ToXContentToBytes implements QueryBuilder<EmptyQueryBuilder> {
3941

4042
public static final String NAME = "empty_query";
4143

4244
/** the one and only empty query builder */
4345
public static final EmptyQueryBuilder PROTOTYPE = new EmptyQueryBuilder();
4446

47+
// prevent instances other than prototype
4548
private EmptyQueryBuilder() {
46-
// prevent other constructors
49+
super(XContentType.JSON);
4750
}
4851

4952
@Override
@@ -52,16 +55,15 @@ public String getName() {
5255
}
5356

5457
@Override
55-
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
56-
// empty
58+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
59+
builder.startObject();
60+
builder.endObject();
61+
return builder;
5762
}
5863

59-
/**
60-
* @returns <tt>null</tt> to signal to caller that this query should be ignored
61-
* in the context of the DSL.
62-
*/
6364
@Override
64-
public Query doToQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
65+
public Query toQuery(QueryParseContext parseContext) throws IOException {
66+
// empty
6567
return null;
6668
}
6769

@@ -72,12 +74,11 @@ public QueryValidationException validate() {
7274
}
7375

7476
@Override
75-
public EmptyQueryBuilder doReadFrom(StreamInput in) throws IOException {
76-
return EmptyQueryBuilder.PROTOTYPE;
77+
public void writeTo(StreamOutput out) throws IOException {
7778
}
7879

7980
@Override
80-
public void doWriteTo(StreamOutput out) throws IOException {
81-
// nothing to serialize
81+
public EmptyQueryBuilder readFrom(StreamInput in) throws IOException {
82+
return EmptyQueryBuilder.PROTOTYPE;
8283
}
8384
}

0 commit comments

Comments
 (0)