apply review comments
This commit is contained in:
parent
4176964358
commit
968561ad49
|
@ -163,7 +163,7 @@ public class TransportValidateQueryAction extends TransportBroadcastAction<Valid
|
|||
protected ShardValidateQueryResponse shardOperation(ShardValidateQueryRequest request) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
||||
IndexShard indexShard = indexService.getShard(request.shardId().id());
|
||||
QueryShardContext queryParserService = indexShard.getQueryShardContext();
|
||||
final QueryShardContext queryShardContext = indexShard.getQueryShardContext();
|
||||
|
||||
boolean valid;
|
||||
String explanation = null;
|
||||
|
@ -178,7 +178,7 @@ public class TransportValidateQueryAction extends TransportBroadcastAction<Valid
|
|||
);
|
||||
SearchContext.setCurrent(searchContext);
|
||||
try {
|
||||
searchContext.parsedQuery(queryParserService.toQuery(request.query()));
|
||||
searchContext.parsedQuery(queryShardContext.toQuery(request.query()));
|
||||
searchContext.preProcess();
|
||||
|
||||
valid = true;
|
||||
|
|
|
@ -236,9 +236,13 @@ public final class IndexSettings {
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the settings and index metadata and notifies all registered settings consumers with the new settings iff at least one setting has changed.
|
||||
*
|
||||
|
|
|
@ -179,7 +179,7 @@ public final class PercolatorQueriesRegistry extends AbstractIndexShardComponent
|
|||
if (type != null) {
|
||||
previousTypes = QueryShardContext.setTypesWithPrevious(type);
|
||||
}
|
||||
QueryShardContext context = queryShardContext.clone();
|
||||
QueryShardContext context = new QueryShardContext(queryShardContext);
|
||||
try {
|
||||
context.reset(parser);
|
||||
// This means that fields in the query need to exist in the mapping prior to registering this query
|
||||
|
|
|
@ -123,6 +123,11 @@ public class QueryShardContext {
|
|||
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() {
|
||||
return new QueryShardContext(indexSettings, client, bitsetFilterCache, indexFieldDataService, mapperService, similarityService, scriptService, indicesQueriesRegistry);
|
||||
}
|
||||
|
@ -348,7 +353,7 @@ public class QueryShardContext {
|
|||
|
||||
public boolean matchesIndices(String... indices) {
|
||||
for (String index : indices) {
|
||||
if (indexSettings.isMatchIndexName(index)) {
|
||||
if (indexSettings.matchesIndexName(index)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ public class TemplateQueryBuilder extends AbstractQueryBuilder<TemplateQueryBuil
|
|||
protected Query doToQuery(QueryShardContext context) throws IOException {
|
||||
BytesReference querySource = context.executeQueryTemplate(template, SearchContext.current());
|
||||
try (XContentParser qSourceParser = XContentFactory.xContent(querySource).createParser(querySource)) {
|
||||
final QueryShardContext contextCopy = context.clone();
|
||||
final QueryShardContext contextCopy = new QueryShardContext(context);
|
||||
contextCopy.reset(qSourceParser);
|
||||
QueryBuilder result = contextCopy.parseContext().parseInnerQueryBuilder();
|
||||
context.combineNamedQueries(contextCopy);
|
||||
|
|
|
@ -106,7 +106,7 @@ public class WrapperQueryBuilder extends AbstractQueryBuilder<WrapperQueryBuilde
|
|||
@Override
|
||||
protected Query doToQuery(QueryShardContext context) throws IOException {
|
||||
try (XContentParser qSourceParser = XContentFactory.xContent(source).createParser(source)) {
|
||||
final QueryShardContext contextCopy = context.clone();
|
||||
final QueryShardContext contextCopy = new QueryShardContext(context);
|
||||
contextCopy.reset(qSourceParser);
|
||||
contextCopy.parseFieldMatcher(context.parseFieldMatcher());
|
||||
QueryBuilder<?> result = contextCopy.parseContext().parseInnerQueryBuilder();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.setCurrent(context);
|
||||
|
||||
try {
|
||||
if (request.scroll() != null) {
|
||||
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);
|
||||
BytesReference run = (BytesReference) executable.run();
|
||||
try (XContentParser parser = XContentFactory.xContent(run).createParser(run)) {
|
||||
QueryParseContext queryParseContext = indicesService.newQueryParserContext();
|
||||
QueryParseContext queryParseContext = new QueryParseContext(indicesService.getIndicesQueryRegistry());
|
||||
queryParseContext.reset(parser);
|
||||
queryParseContext.parseFieldMatcher(parseFieldMatcher);
|
||||
parseSource(context, SearchSourceBuilder.parseSearchSource(parser, queryParseContext));
|
||||
|
@ -1180,7 +1181,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> imp
|
|||
try {
|
||||
long now = System.nanoTime();
|
||||
final IndexService indexService = indicesService.indexServiceSafe(indexShard.shardId().index().name());
|
||||
QueryParseContext queryParseContext = indicesService.newQueryParserContext();
|
||||
QueryParseContext queryParseContext = new QueryParseContext(indicesService.getIndicesQueryRegistry());
|
||||
queryParseContext.parseFieldMatcher(indexService.getIndexSettings().getParseFieldMatcher());
|
||||
ShardSearchRequest request = new ShardSearchLocalRequest(indexShard.shardId(), indexShard.getIndexSettings()
|
||||
.getNumberOfShards(),
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
protected static QueryShardContext createShardContext() {
|
||||
QueryShardContext queryCreationContext = queryShardContext.clone();
|
||||
QueryShardContext queryCreationContext = new QueryShardContext(queryShardContext);
|
||||
queryCreationContext.reset();
|
||||
queryCreationContext.parseFieldMatcher(ParseFieldMatcher.STRICT);
|
||||
return queryCreationContext;
|
||||
|
|
|
@ -56,7 +56,7 @@ public class WrapperQueryBuilderTests extends AbstractQueryTestCase<WrapperQuery
|
|||
@Override
|
||||
protected void doAssertLuceneQuery(WrapperQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException {
|
||||
try (XContentParser qSourceParser = XContentFactory.xContent(queryBuilder.source()).createParser(queryBuilder.source())) {
|
||||
final QueryShardContext contextCopy = context.clone();
|
||||
final QueryShardContext contextCopy = new QueryShardContext(context);
|
||||
contextCopy.reset(qSourceParser);
|
||||
QueryBuilder<?> innerQuery = contextCopy.parseContext().parseInnerQueryBuilder();
|
||||
Query expected = innerQuery.toQuery(context);
|
||||
|
|
Loading…
Reference in New Issue