apply review comments

This commit is contained in:
Simon Willnauer 2015-11-03 17:09:32 +01:00
parent 4176964358
commit 968561ad49
10 changed files with 26 additions and 13 deletions

View File

@ -163,7 +163,7 @@ public class TransportValidateQueryAction extends TransportBroadcastAction<Valid
protected ShardValidateQueryResponse shardOperation(ShardValidateQueryRequest request) { protected ShardValidateQueryResponse shardOperation(ShardValidateQueryRequest request) {
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex()); IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
IndexShard indexShard = indexService.getShard(request.shardId().id()); IndexShard indexShard = indexService.getShard(request.shardId().id());
QueryShardContext queryParserService = indexShard.getQueryShardContext(); final QueryShardContext queryShardContext = indexShard.getQueryShardContext();
boolean valid; boolean valid;
String explanation = null; String explanation = null;
@ -178,7 +178,7 @@ public class TransportValidateQueryAction extends TransportBroadcastAction<Valid
); );
SearchContext.setCurrent(searchContext); SearchContext.setCurrent(searchContext);
try { try {
searchContext.parsedQuery(queryParserService.toQuery(request.query())); searchContext.parsedQuery(queryShardContext.toQuery(request.query()));
searchContext.preProcess(); searchContext.preProcess();
valid = true; valid = true;

View File

@ -236,9 +236,13 @@ public final class IndexSettings {
*/ */
public ParseFieldMatcher getParseFieldMatcher() { return parseFieldMatcher; } public ParseFieldMatcher getParseFieldMatcher() { return parseFieldMatcher; }
public boolean isMatchIndexName(String expression) { /**
* Returns <code>true</code> if the given expression matches the index name or one of it's aliases
*/
public boolean matchesIndexName(String expression) {
return indexNameMatcher.test(expression); return indexNameMatcher.test(expression);
} }
/** /**
* Updates the settings and index metadata and notifies all registered settings consumers with the new settings iff at least one setting has changed. * Updates the settings and index metadata and notifies all registered settings consumers with the new settings iff at least one setting has changed.
* *

View File

@ -179,7 +179,7 @@ public final class PercolatorQueriesRegistry extends AbstractIndexShardComponent
if (type != null) { if (type != null) {
previousTypes = QueryShardContext.setTypesWithPrevious(type); previousTypes = QueryShardContext.setTypesWithPrevious(type);
} }
QueryShardContext context = queryShardContext.clone(); QueryShardContext context = new QueryShardContext(queryShardContext);
try { try {
context.reset(parser); context.reset(parser);
// This means that fields in the query need to exist in the mapping prior to registering this query // This means that fields in the query need to exist in the mapping prior to registering this query

View File

@ -123,6 +123,11 @@ public class QueryShardContext {
this.parseContext = new QueryParseContext(indicesQueriesRegistry); this.parseContext = new QueryParseContext(indicesQueriesRegistry);
} }
public QueryShardContext(QueryShardContext source) {
this(source.indexSettings, source.client, source.bitsetFilterCache, source.indexFieldDataService, source.mapperService, source.similarityService, source.scriptService, source.indicesQueriesRegistry);
}
public QueryShardContext clone() { public QueryShardContext clone() {
return new QueryShardContext(indexSettings, client, bitsetFilterCache, indexFieldDataService, mapperService, similarityService, scriptService, indicesQueriesRegistry); return new QueryShardContext(indexSettings, client, bitsetFilterCache, indexFieldDataService, mapperService, similarityService, scriptService, indicesQueriesRegistry);
} }
@ -348,7 +353,7 @@ public class QueryShardContext {
public boolean matchesIndices(String... indices) { public boolean matchesIndices(String... indices) {
for (String index : indices) { for (String index : indices) {
if (indexSettings.isMatchIndexName(index)) { if (indexSettings.matchesIndexName(index)) {
return true; return true;
} }
} }

View File

@ -102,7 +102,7 @@ public class TemplateQueryBuilder extends AbstractQueryBuilder<TemplateQueryBuil
protected Query doToQuery(QueryShardContext context) throws IOException { protected Query doToQuery(QueryShardContext context) throws IOException {
BytesReference querySource = context.executeQueryTemplate(template, SearchContext.current()); BytesReference querySource = context.executeQueryTemplate(template, SearchContext.current());
try (XContentParser qSourceParser = XContentFactory.xContent(querySource).createParser(querySource)) { try (XContentParser qSourceParser = XContentFactory.xContent(querySource).createParser(querySource)) {
final QueryShardContext contextCopy = context.clone(); final QueryShardContext contextCopy = new QueryShardContext(context);
contextCopy.reset(qSourceParser); contextCopy.reset(qSourceParser);
QueryBuilder result = contextCopy.parseContext().parseInnerQueryBuilder(); QueryBuilder result = contextCopy.parseContext().parseInnerQueryBuilder();
context.combineNamedQueries(contextCopy); context.combineNamedQueries(contextCopy);

View File

@ -106,7 +106,7 @@ public class WrapperQueryBuilder extends AbstractQueryBuilder<WrapperQueryBuilde
@Override @Override
protected Query doToQuery(QueryShardContext context) throws IOException { protected Query doToQuery(QueryShardContext context) throws IOException {
try (XContentParser qSourceParser = XContentFactory.xContent(source).createParser(source)) { try (XContentParser qSourceParser = XContentFactory.xContent(source).createParser(source)) {
final QueryShardContext contextCopy = context.clone(); final QueryShardContext contextCopy = new QueryShardContext(context);
contextCopy.reset(qSourceParser); contextCopy.reset(qSourceParser);
contextCopy.parseFieldMatcher(context.parseFieldMatcher()); contextCopy.parseFieldMatcher(context.parseFieldMatcher());
QueryBuilder<?> result = contextCopy.parseContext().parseInnerQueryBuilder(); QueryBuilder<?> result = contextCopy.parseContext().parseInnerQueryBuilder();

View File

@ -799,7 +799,10 @@ public class IndicesService extends AbstractLifecycleComponent<IndicesService> i
} }
} }
public QueryParseContext newQueryParserContext() { /**
return new QueryParseContext(indicesQueriesRegistry); * Returns this nodes {@link IndicesQueriesRegistry}
*/
public IndicesQueriesRegistry getIndicesQueryRegistry() {
return indicesQueriesRegistry;
} }
} }

View File

@ -551,6 +551,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> imp
SearchContext context = new DefaultSearchContext(idGenerator.incrementAndGet(), request, shardTarget, engineSearcher, indexService, indexShard, scriptService, pageCacheRecycler, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher, defaultSearchTimeout); SearchContext context = new DefaultSearchContext(idGenerator.incrementAndGet(), request, shardTarget, engineSearcher, indexService, indexShard, scriptService, pageCacheRecycler, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher, defaultSearchTimeout);
SearchContext.setCurrent(context); SearchContext.setCurrent(context);
try { try {
if (request.scroll() != null) { if (request.scroll() != null) {
context.scrollContext(new ScrollContext()); context.scrollContext(new ScrollContext());
@ -560,7 +561,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> imp
ExecutableScript executable = this.scriptService.executable(request.template(), ScriptContext.Standard.SEARCH, context); ExecutableScript executable = this.scriptService.executable(request.template(), ScriptContext.Standard.SEARCH, context);
BytesReference run = (BytesReference) executable.run(); BytesReference run = (BytesReference) executable.run();
try (XContentParser parser = XContentFactory.xContent(run).createParser(run)) { try (XContentParser parser = XContentFactory.xContent(run).createParser(run)) {
QueryParseContext queryParseContext = indicesService.newQueryParserContext(); QueryParseContext queryParseContext = new QueryParseContext(indicesService.getIndicesQueryRegistry());
queryParseContext.reset(parser); queryParseContext.reset(parser);
queryParseContext.parseFieldMatcher(parseFieldMatcher); queryParseContext.parseFieldMatcher(parseFieldMatcher);
parseSource(context, SearchSourceBuilder.parseSearchSource(parser, queryParseContext)); parseSource(context, SearchSourceBuilder.parseSearchSource(parser, queryParseContext));
@ -1180,7 +1181,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> imp
try { try {
long now = System.nanoTime(); long now = System.nanoTime();
final IndexService indexService = indicesService.indexServiceSafe(indexShard.shardId().index().name()); final IndexService indexService = indicesService.indexServiceSafe(indexShard.shardId().index().name());
QueryParseContext queryParseContext = indicesService.newQueryParserContext(); QueryParseContext queryParseContext = new QueryParseContext(indicesService.getIndicesQueryRegistry());
queryParseContext.parseFieldMatcher(indexService.getIndexSettings().getParseFieldMatcher()); queryParseContext.parseFieldMatcher(indexService.getIndexSettings().getParseFieldMatcher());
ShardSearchRequest request = new ShardSearchLocalRequest(indexShard.shardId(), indexShard.getIndexSettings() ShardSearchRequest request = new ShardSearchLocalRequest(indexShard.shardId(), indexShard.getIndexSettings()
.getNumberOfShards(), .getNumberOfShards(),

View File

@ -577,7 +577,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
* @return a new {@link QueryShardContext} based on the base test index and queryParserService * @return a new {@link QueryShardContext} based on the base test index and queryParserService
*/ */
protected static QueryShardContext createShardContext() { protected static QueryShardContext createShardContext() {
QueryShardContext queryCreationContext = queryShardContext.clone(); QueryShardContext queryCreationContext = new QueryShardContext(queryShardContext);
queryCreationContext.reset(); queryCreationContext.reset();
queryCreationContext.parseFieldMatcher(ParseFieldMatcher.STRICT); queryCreationContext.parseFieldMatcher(ParseFieldMatcher.STRICT);
return queryCreationContext; return queryCreationContext;

View File

@ -56,7 +56,7 @@ public class WrapperQueryBuilderTests extends AbstractQueryTestCase<WrapperQuery
@Override @Override
protected void doAssertLuceneQuery(WrapperQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { protected void doAssertLuceneQuery(WrapperQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException {
try (XContentParser qSourceParser = XContentFactory.xContent(queryBuilder.source()).createParser(queryBuilder.source())) { try (XContentParser qSourceParser = XContentFactory.xContent(queryBuilder.source()).createParser(queryBuilder.source())) {
final QueryShardContext contextCopy = context.clone(); final QueryShardContext contextCopy = new QueryShardContext(context);
contextCopy.reset(qSourceParser); contextCopy.reset(qSourceParser);
QueryBuilder<?> innerQuery = contextCopy.parseContext().parseInnerQueryBuilder(); QueryBuilder<?> innerQuery = contextCopy.parseContext().parseInnerQueryBuilder();
Query expected = innerQuery.toQuery(context); Query expected = innerQuery.toQuery(context);