From 2e892185f0131b5a4f820e5b01de7cf2994fe15b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Wed, 17 Aug 2016 11:54:07 +0200 Subject: [PATCH] Adapting to introduction of SearchRequestParers on master --- .../index/rankeval/RankEvalContext.java | 14 ++++++------- .../index/rankeval/RestRankEvalAction.java | 19 ++++++----------- .../index/rankeval/QuerySpecTests.java | 21 +++++++++---------- .../index/rankeval/RatedDocumentTests.java | 2 +- 4 files changed, 23 insertions(+), 33 deletions(-) diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalContext.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalContext.java index 780585d978d..496dcbca02a 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalContext.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalContext.java @@ -23,30 +23,28 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.suggest.Suggesters; public class RankEvalContext implements ParseFieldMatcherSupplier { + private final SearchRequestParsers searchRequestParsers; private final ParseFieldMatcher parseFieldMatcher; - private final AggregatorParsers aggs; - private final Suggesters suggesters; private final QueryParseContext parseContext; - public RankEvalContext(ParseFieldMatcher parseFieldMatcher, QueryParseContext parseContext, AggregatorParsers aggs, - Suggesters suggesters) { + public RankEvalContext(ParseFieldMatcher parseFieldMatcher, QueryParseContext parseContext, SearchRequestParsers searchRequestParsers) { this.parseFieldMatcher = parseFieldMatcher; - this.aggs = aggs; - this.suggesters = suggesters; + this.searchRequestParsers = searchRequestParsers; this.parseContext = parseContext; } public Suggesters getSuggesters() { - return this.suggesters; + return searchRequestParsers.suggesters; } public AggregatorParsers getAggs() { - return this.aggs; + return searchRequestParsers.aggParsers; } @Override diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java index 4f369eb4b21..8316dc49db3 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java @@ -30,15 +30,13 @@ import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; -import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.search.aggregations.AggregatorParsers; -import org.elasticsearch.search.suggest.Suggesters; +import org.elasticsearch.search.SearchRequestParsers; import java.io.IOException; import java.util.Arrays; @@ -165,17 +163,12 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; * */ public class RestRankEvalAction extends BaseRestHandler { - private IndicesQueriesRegistry queryRegistry; - private AggregatorParsers aggregators; - private Suggesters suggesters; + private SearchRequestParsers searchRequestParsers; @Inject - public RestRankEvalAction(Settings settings, RestController controller, IndicesQueriesRegistry queryRegistry, - AggregatorParsers aggParsers, Suggesters suggesters) { + public RestRankEvalAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) { super(settings); - this.queryRegistry = queryRegistry; - this.aggregators = aggParsers; - this.suggesters = suggesters; + this.searchRequestParsers = searchRequestParsers; controller.registerHandler(GET, "/_rank_eval", this); controller.registerHandler(POST, "/_rank_eval", this); controller.registerHandler(GET, "/{index}/_rank_eval", this); @@ -189,11 +182,11 @@ public class RestRankEvalAction extends BaseRestHandler { RankEvalRequest rankEvalRequest = new RankEvalRequest(); BytesReference restContent = RestActions.hasBodyContent(request) ? RestActions.getRestContent(request) : null; try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { - QueryParseContext parseContext = new QueryParseContext(queryRegistry, parser, parseFieldMatcher); + QueryParseContext parseContext = new QueryParseContext(searchRequestParsers.queryParsers, parser, parseFieldMatcher); if (restContent != null) { parseRankEvalRequest(rankEvalRequest, request, // TODO can we get rid of aggregators parsers and suggesters? - new RankEvalContext(parseFieldMatcher, parseContext, aggregators, suggesters)); + new RankEvalContext(parseFieldMatcher, parseContext, searchRequestParsers)); } } client.execute(RankEvalAction.INSTANCE, rankEvalRequest, new RestToXContentListener(channel)); diff --git a/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/QuerySpecTests.java b/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/QuerySpecTests.java index ce0c367af7f..8d77e002a12 100644 --- a/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/QuerySpecTests.java +++ b/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/QuerySpecTests.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.search.SearchModule; +import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.test.ESTestCase; @@ -40,28 +41,26 @@ import static java.util.Collections.emptyList; public class QuerySpecTests extends ESTestCase { - private static IndicesQueriesRegistry queriesRegistry; private static SearchModule searchModule; - private static Suggesters suggesters; - private static AggregatorParsers aggsParsers; + private static SearchRequestParsers searchRequestParsers; /** * setup for the whole base test class */ @BeforeClass public static void init() throws IOException { - aggsParsers = new AggregatorParsers(new ParseFieldRegistry<>("aggregation"), new ParseFieldRegistry<>("aggregation_pipes")); + AggregatorParsers aggsParsers = new AggregatorParsers(new ParseFieldRegistry<>("aggregation"), + new ParseFieldRegistry<>("aggregation_pipes")); searchModule = new SearchModule(Settings.EMPTY, false, emptyList()); - queriesRegistry = searchModule.getQueryParserRegistry(); - suggesters = searchModule.getSuggesters(); + IndicesQueriesRegistry queriesRegistry = searchModule.getQueryParserRegistry(); + Suggesters suggesters = searchModule.getSuggesters(); + searchRequestParsers = new SearchRequestParsers(queriesRegistry, aggsParsers, suggesters); } @AfterClass public static void afterClass() throws Exception { - queriesRegistry = null; searchModule = null; - suggesters = null; - aggsParsers = null; + searchRequestParsers = null; } // TODO add some sort of roundtrip testing like we have now for queries? @@ -85,9 +84,9 @@ public class QuerySpecTests extends ESTestCase { + " {\"key\": {\"index\": \"test\", \"type\": \"testtype\", \"doc_id\": \"3\"}, \"rating\" : 1 }]\n" + "}"; XContentParser parser = XContentFactory.xContent(querySpecString).createParser(querySpecString); - QueryParseContext queryContext = new QueryParseContext(queriesRegistry, parser, ParseFieldMatcher.STRICT); + QueryParseContext queryContext = new QueryParseContext(searchRequestParsers.queryParsers, parser, ParseFieldMatcher.STRICT); RankEvalContext rankContext = new RankEvalContext(ParseFieldMatcher.STRICT, queryContext, - aggsParsers, suggesters); + searchRequestParsers); QuerySpec specification = QuerySpec.fromXContent(parser, rankContext); assertEquals("my_qa_query", specification.getSpecId()); assertNotNull(specification.getTestRequest()); diff --git a/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RatedDocumentTests.java b/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RatedDocumentTests.java index ba0b1bece22..6e48b72d38e 100644 --- a/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RatedDocumentTests.java +++ b/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RatedDocumentTests.java @@ -48,7 +48,7 @@ public class RatedDocumentTests extends ESTestCase { XContentParser itemParser = XContentHelper.createParser(shuffled.bytes()); itemParser.nextToken(); - RankEvalContext context = new RankEvalContext(ParseFieldMatcher.STRICT, null, null, null); + RankEvalContext context = new RankEvalContext(ParseFieldMatcher.STRICT, null, null); RatedDocument parsedItem = RatedDocument.fromXContent(itemParser, context); assertNotSame(testItem, parsedItem); assertEquals(testItem, parsedItem);