Adapting to introduction of SearchRequestParers on master
This commit is contained in:
parent
ff17b9b38f
commit
2e892185f0
|
@ -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
|
||||
|
|
|
@ -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<RankEvalResponse>(channel));
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue