From 4841c5a3d38de95eedef071459abeace5c56e9bd Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 6 Apr 2016 14:35:49 -0400 Subject: [PATCH] Cut CustomQueryParserIT to registerQuery This is the last place inside of ES other than SearchModule. --- .../query/plugin/DummyQueryParserPlugin.java | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java b/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java index f084705affd..211aebf869e 100644 --- a/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java +++ b/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.AbstractQueryBuilder; import org.elasticsearch.index.query.QueryParseContext; -import org.elasticsearch.index.query.QueryParser; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchModule; @@ -50,17 +49,24 @@ public class DummyQueryParserPlugin extends Plugin { } public void onModule(SearchModule module) { - module.registerQueryParser(new DummyQueryParser(), new ParseField(DummyQueryBuilder.NAME)); + module.registerQuery(new DummyQueryBuilder()::readFrom, DummyQueryBuilder::fromXContent, DummyQueryBuilder.QUERY_NAME_FIELD); } public static class DummyQueryBuilder extends AbstractQueryBuilder { private static final String NAME = "dummy"; + private static final ParseField QUERY_NAME_FIELD = new ParseField(NAME); @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NAME).endObject(); } + public static DummyQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException { + XContentParser.Token token = parseContext.parser().nextToken(); + assert token == XContentParser.Token.END_OBJECT; + return new DummyQueryBuilder(); + } + @Override protected Query doToQuery(QueryShardContext context) throws IOException { return new DummyQuery(context.isFilter()); @@ -92,20 +98,6 @@ public class DummyQueryParserPlugin extends Plugin { } } - public static class DummyQueryParser implements QueryParser { - @Override - public DummyQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException { - XContentParser.Token token = parseContext.parser().nextToken(); - assert token == XContentParser.Token.END_OBJECT; - return new DummyQueryBuilder(); - } - - @Override - public DummyQueryBuilder getBuilderPrototype() { - return new DummyQueryBuilder(); - } - } - public static class DummyQuery extends Query { public final boolean isFilter; private final Query matchAllDocsQuery = new MatchAllDocsQuery();