Query refactoring: fixed some leftover generics warnings

Leftover after adding the query builder type to QueryParser. getBuilderPrototype is better typed now and doesn't require unchecked cast anymore. Fixed also some Tuple usage without types.
This commit is contained in:
javanna 2015-08-13 17:47:47 +02:00 committed by Luca Cavanna
parent 135aab0092
commit babfea0ab7
3 changed files with 16 additions and 15 deletions

View File

@ -116,7 +116,9 @@ public class IndexQueryParserService extends AbstractIndexComponent {
return this.queryStringLenient;
}
public QueryParser queryParser(String name) {
//norelease we might want to get rid of this as it was temporarily introduced for our default doToQuery impl
//seems to be used only in tests
public QueryParser<? extends QueryBuilder<? extends QueryBuilder>> queryParser(String name) {
return indicesQueriesRegistry.queryParsers().get(name);
}
@ -233,8 +235,7 @@ public class IndexQueryParserService extends AbstractIndexComponent {
@Nullable
public QueryBuilder parseInnerQueryBuilder(QueryParseContext parseContext) throws IOException {
parseContext.parseFieldMatcher(parseFieldMatcher);
QueryBuilder query = parseContext.parseInnerQueryBuilder();
return query;
return parseContext.parseInnerQueryBuilder();
}
@Nullable

View File

@ -35,13 +35,13 @@ import java.util.Set;
public class IndicesQueriesRegistry extends AbstractComponent {
private ImmutableMap<String, QueryParser> queryParsers;
private ImmutableMap<String, QueryParser<? extends QueryBuilder<? extends QueryBuilder>>> queryParsers;
@Inject
public IndicesQueriesRegistry(Settings settings, Set<QueryParser> injectedQueryParsers, NamedWriteableRegistry namedWriteableRegistry) {
public IndicesQueriesRegistry(Settings settings, Set<QueryParser<? extends QueryBuilder<? extends QueryBuilder>>> injectedQueryParsers, NamedWriteableRegistry namedWriteableRegistry) {
super(settings);
Map<String, QueryParser> queryParsers = Maps.newHashMap();
for (QueryParser queryParser : injectedQueryParsers) {
Map<String, QueryParser<? extends QueryBuilder<? extends QueryBuilder>>> queryParsers = Maps.newHashMap();
for (QueryParser<? extends QueryBuilder<? extends QueryBuilder>> queryParser : injectedQueryParsers) {
for (String name : queryParser.names()) {
queryParsers.put(name, queryParser);
}
@ -56,7 +56,7 @@ public class IndicesQueriesRegistry extends AbstractComponent {
/**
* Returns all the registered query parsers
*/
public ImmutableMap<String, QueryParser> queryParsers() {
public ImmutableMap<String, QueryParser<? extends QueryBuilder<? extends QueryBuilder>>> queryParsers() {
return queryParsers;
}
}

View File

@ -244,9 +244,9 @@ public abstract class BaseQueryTestCase<QB extends AbstractQueryBuilder<QB>> ext
try (BytesStreamOutput output = new BytesStreamOutput()) {
firstQuery.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) {
QueryBuilder<? extends QueryBuilder> prototype = queryParserService.queryParser(firstQuery.getWriteableName()).getBuilderPrototype();
@SuppressWarnings("unchecked")
QB secondQuery = (QB)prototype.readFrom(in);
QueryParser<QB> queryParser = (QueryParser<QB>)queryParserService.queryParser(firstQuery.getWriteableName());
QB secondQuery = queryParser.getBuilderPrototype().readFrom(in);
//query _name never should affect the result of toQuery, we randomly set it to make sure
if (randomBoolean()) {
secondQuery.queryName(secondQuery.queryName() == null ? randomAsciiOfLengthBetween(1, 30) : secondQuery.queryName() + randomAsciiOfLengthBetween(1, 10));
@ -269,7 +269,8 @@ public abstract class BaseQueryTestCase<QB extends AbstractQueryBuilder<QB>> ext
/**
* Few queries allow you to set the boost and queryName but don't do anything with it. This method allows
* to disable boost and queryName related tests for those queries.
* to disable boost and queryName related tests for those queries. Those queries are easy to identify: their parsers
* don't parse `boost` and `_name` as they don't apply to the specific query e.g. filter query or wrapper query
*/
protected boolean supportsBoostAndQueryName() {
return true;
@ -328,8 +329,7 @@ public abstract class BaseQueryTestCase<QB extends AbstractQueryBuilder<QB>> ext
* @return a new {@link QueryParseContext} based on the base test index and queryParserService
*/
protected static QueryParseContext createParseContext() {
QueryParseContext parseContext = createShardContext().parseContext();
return parseContext;
return createShardContext().parseContext();
}
protected static void assertQueryHeader(XContentParser parser, String expectedParserName) throws IOException {
@ -410,7 +410,7 @@ public abstract class BaseQueryTestCase<QB extends AbstractQueryBuilder<QB>> ext
protected static Tuple<String, Object> getRandomFieldNameAndValue() {
// if no type is set then return random field name and value
if (currentTypes == null || currentTypes.length == 0) {
return new Tuple(randomAsciiOfLengthBetween(1, 10), randomAsciiOfLengthBetween(1, 50));
return new Tuple<String, Object>(randomAsciiOfLengthBetween(1, 10), randomAsciiOfLengthBetween(1, 50));
}
// mapped fields
String fieldName = randomFrom(mappedFieldNames);
@ -437,7 +437,7 @@ public abstract class BaseQueryTestCase<QB extends AbstractQueryBuilder<QB>> ext
if (randomBoolean()) {
fieldName = randomAsciiOfLengthBetween(1, 10);
}
return new Tuple(fieldName, value);
return new Tuple<>(fieldName, value);
}
protected static Fuzziness randomFuzziness(String fieldName) {