Cut CustomQueryParserIT to registerQuery

This is the last place inside of ES other than SearchModule.
This commit is contained in:
Nik Everett 2016-04-06 14:35:49 -04:00
parent f157dae053
commit 4841c5a3d3
1 changed files with 8 additions and 16 deletions

View File

@ -30,7 +30,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.AbstractQueryBuilder; import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryParser;
import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.SearchModule; import org.elasticsearch.search.SearchModule;
@ -50,17 +49,24 @@ public class DummyQueryParserPlugin extends Plugin {
} }
public void onModule(SearchModule module) { 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<DummyQueryBuilder> { public static class DummyQueryBuilder extends AbstractQueryBuilder<DummyQueryBuilder> {
private static final String NAME = "dummy"; private static final String NAME = "dummy";
private static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
@Override @Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException { protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(NAME).endObject(); 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 @Override
protected Query doToQuery(QueryShardContext context) throws IOException { protected Query doToQuery(QueryShardContext context) throws IOException {
return new DummyQuery(context.isFilter()); return new DummyQuery(context.isFilter());
@ -92,20 +98,6 @@ public class DummyQueryParserPlugin extends Plugin {
} }
} }
public static class DummyQueryParser implements QueryParser<DummyQueryBuilder> {
@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 static class DummyQuery extends Query {
public final boolean isFilter; public final boolean isFilter;
private final Query matchAllDocsQuery = new MatchAllDocsQuery(); private final Query matchAllDocsQuery = new MatchAllDocsQuery();