diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/IndexQueryParserModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/IndexQueryParserModule.java index 28093f96e3c21..00902da673437 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/IndexQueryParserModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/IndexQueryParserModule.java @@ -144,6 +144,7 @@ public void processXContentQueryFilter(String name, Class indexQueryParsers; - public IndexQueryParserService(Index index, MapperService mapperService, IndexCache indexCache, IndexEngine indexEngine, AnalysisService analysisService) { - this(index, EMPTY_SETTINGS, new ScriptService(EMPTY_SETTINGS), mapperService, indexCache, indexEngine, analysisService, null, null); - } - @Inject public IndexQueryParserService(Index index, @IndexSettings Settings indexSettings, - ScriptService scriptService, - MapperService mapperService, IndexCache indexCache, - IndexEngine indexEngine, AnalysisService analysisService, - @Nullable SimilarityService similarityService, @Nullable Map indexQueryParsersFactories) { super(index, indexSettings); Map queryParserGroupSettings; @@ -81,11 +66,6 @@ public IndexQueryParserService(Index index, MapperService mapperService, IndexCa qparsers.put(qparserName, entry.getValue().create(qparserName, qparserSettings)); } } - if (!qparsers.containsKey(Defaults.DEFAULT)) { - IndexQueryParser defaultQueryParser = new XContentIndexQueryParser(index, indexSettings, scriptService, mapperService, indexCache, indexEngine, analysisService, similarityService, null, null, Defaults.DEFAULT, null); - qparsers.put(Defaults.DEFAULT, defaultQueryParser); - } - indexQueryParsers = ImmutableMap.copyOf(qparsers); defaultIndexQueryParser = indexQueryParser(Defaults.DEFAULT); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolFilterParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolFilterParser.java index 8d40eab05431a..aac02082ad15d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolFilterParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolFilterParser.java @@ -38,12 +38,14 @@ */ public class BoolFilterParser extends AbstractIndexComponent implements XContentFilterParser { + public static final String NAME = "bool"; + @Inject public BoolFilterParser(Index index, @IndexSettings Settings settings) { super(index, settings); } @Override public String[] names() { - return new String[]{"bool"}; + return new String[]{NAME}; } @Override public Filter parse(QueryParseContext parseContext) throws IOException, QueryParsingException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolQueryParser.java index 97946adf216b7..a6e5bf0e83fc3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolQueryParser.java @@ -41,12 +41,14 @@ */ public class BoolQueryParser extends AbstractIndexComponent implements XContentQueryParser { + public static final String NAME = "bool"; + @Inject public BoolQueryParser(Index index, @IndexSettings Settings settings) { super(index, settings); } @Override public String[] names() { - return new String[]{"bool"}; + return new String[]{NAME}; } @Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyLikeThisFieldQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyLikeThisFieldQueryParser.java index 2a4586ceecb23..9f5120c846285 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyLikeThisFieldQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyLikeThisFieldQueryParser.java @@ -23,6 +23,7 @@ import org.apache.lucene.search.FuzzyLikeThisQuery; import org.apache.lucene.search.Query; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.AbstractIndexComponent; @@ -53,7 +54,7 @@ public class FuzzyLikeThisFieldQueryParser extends AbstractIndexComponent implem public static final String NAME = "flt_field"; - public FuzzyLikeThisFieldQueryParser(Index index, @IndexSettings Settings indexSettings) { + @Inject public FuzzyLikeThisFieldQueryParser(Index index, @IndexSettings Settings indexSettings) { super(index, indexSettings); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyLikeThisQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyLikeThisQueryParser.java index b15eea34673df..93c48cb24eff4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyLikeThisQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyLikeThisQueryParser.java @@ -22,6 +22,7 @@ import org.apache.lucene.search.FuzzyLikeThisQuery; import org.apache.lucene.search.Query; import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.AbstractIndexComponent; @@ -51,7 +52,7 @@ public class FuzzyLikeThisQueryParser extends AbstractIndexComponent implements public static final String NAME = "flt"; - public FuzzyLikeThisQueryParser(Index index, @IndexSettings Settings indexSettings) { + @Inject public FuzzyLikeThisQueryParser(Index index, @IndexSettings Settings indexSettings) { super(index, indexSettings); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyQueryParser.java index be71aa1e2161e..0eee5a6c1b770 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FuzzyQueryParser.java @@ -22,6 +22,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.Query; +import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.AbstractIndexComponent; @@ -41,7 +42,7 @@ public class FuzzyQueryParser extends AbstractIndexComponent implements XContent public static final String NAME = "fuzzy"; - public FuzzyQueryParser(Index index, @IndexSettings Settings indexSettings) { + @Inject public FuzzyQueryParser(Index index, @IndexSettings Settings indexSettings) { super(index, indexSettings); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MoreLikeThisFieldQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MoreLikeThisFieldQueryParser.java index 5d2007000b5cb..74aabed97e6f2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MoreLikeThisFieldQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MoreLikeThisFieldQueryParser.java @@ -22,6 +22,7 @@ import org.apache.lucene.search.Query; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.Sets; +import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.search.MoreLikeThisQuery; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; @@ -43,7 +44,7 @@ public class MoreLikeThisFieldQueryParser extends AbstractIndexComponent impleme public static final String NAME = "mlt_field"; - public MoreLikeThisFieldQueryParser(Index index, @IndexSettings Settings indexSettings) { + @Inject public MoreLikeThisFieldQueryParser(Index index, @IndexSettings Settings indexSettings) { super(index, indexSettings); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MoreLikeThisQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MoreLikeThisQueryParser.java index 74443dafdda56..d403df7a490fb 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MoreLikeThisQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MoreLikeThisQueryParser.java @@ -22,6 +22,7 @@ import org.apache.lucene.search.Query; import org.elasticsearch.common.collect.Lists; import org.elasticsearch.common.collect.Sets; +import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.search.MoreLikeThisQuery; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; @@ -42,7 +43,7 @@ public class MoreLikeThisQueryParser extends AbstractIndexComponent implements X public static final String NAME = "mlt"; - public MoreLikeThisQueryParser(Index index, @IndexSettings Settings indexSettings) { + @Inject public MoreLikeThisQueryParser(Index index, @IndexSettings Settings indexSettings) { super(index, indexSettings); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryParseContext.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryParseContext.java index 70f6a05da9d0d..2a02a4299d65d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryParseContext.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryParseContext.java @@ -50,17 +50,7 @@ public class QueryParseContext { private final Index index; - private final ScriptService scriptService; - - private final MapperService mapperService; - - private final SimilarityService similarityService; - - private final IndexCache indexCache; - - private final IndexEngine indexEngine; - - private final XContentQueryParserRegistry queryParserRegistry; + XContentIndexQueryParser indexQueryParser; private final Map namedFilters = Maps.newHashMap(); @@ -70,17 +60,9 @@ public class QueryParseContext { private XContentParser parser; - public QueryParseContext(Index index, XContentQueryParserRegistry queryParserRegistry, - ScriptService scriptService, - MapperService mapperService, SimilarityService similarityService, - IndexCache indexCache, IndexEngine indexEngine) { + public QueryParseContext(Index index, XContentIndexQueryParser indexQueryParser) { this.index = index; - this.queryParserRegistry = queryParserRegistry; - this.scriptService = scriptService; - this.mapperService = mapperService; - this.similarityService = similarityService; - this.indexCache = indexCache; - this.indexEngine = indexEngine; + this.indexQueryParser = indexQueryParser; } public void reset(XContentParser jp) { @@ -93,27 +75,27 @@ public XContentParser parser() { } public ScriptService scriptService() { - return scriptService; + return indexQueryParser.scriptService; } public MapperService mapperService() { - return mapperService; + return indexQueryParser.mapperService; } public IndexEngine indexEngine() { - return this.indexEngine; + return indexQueryParser.indexEngine; } @Nullable public SimilarityService similarityService() { - return this.similarityService; + return indexQueryParser.similarityService; } public Similarity searchSimilarity() { - return similarityService != null ? similarityService.defaultSearchSimilarity() : null; + return indexQueryParser.similarityService != null ? indexQueryParser.similarityService.defaultSearchSimilarity() : null; } public IndexCache indexCache() { - return indexCache; + return indexQueryParser.indexCache; } public MapperQueryParser queryParser(QueryParserSettings settings) { @@ -127,7 +109,7 @@ public MultiFieldMapperQueryParser queryParser(MultiFieldQueryParserSettings set } public Filter cacheFilterIfPossible(Filter filter) { - return indexCache.filter().cache(filter); + return indexQueryParser.indexCache.filter().cache(filter); } public void addNamedFilter(String name, Filter filter) { @@ -155,7 +137,7 @@ public Query parseInnerQuery() throws IOException, QueryParsingException { token = parser.nextToken(); assert token == XContentParser.Token.START_OBJECT || token == XContentParser.Token.START_ARRAY; - XContentQueryParser queryParser = queryParserRegistry.queryParser(queryName); + XContentQueryParser queryParser = indexQueryParser.queryParser(queryName); if (queryParser == null) { throw new QueryParsingException(index, "No query parser registered for [" + queryName + "]"); } @@ -181,7 +163,7 @@ public Filter parseInnerFilter() throws IOException, QueryParsingException { token = parser.nextToken(); assert token == XContentParser.Token.START_OBJECT || token == XContentParser.Token.START_ARRAY; - XContentFilterParser filterParser = queryParserRegistry.filterParser(queryName); + XContentFilterParser filterParser = indexQueryParser.filterParser(queryName); if (filterParser == null) { throw new QueryParsingException(index, "No query parser registered for [" + queryName + "]"); } @@ -194,7 +176,7 @@ public Filter parseInnerFilter() throws IOException, QueryParsingException { } public FieldMapper fieldMapper(String name) { - FieldMappers fieldMappers = mapperService.smartNameFieldMappers(name); + FieldMappers fieldMappers = indexQueryParser.mapperService.smartNameFieldMappers(name); if (fieldMappers == null) { return null; } @@ -210,6 +192,6 @@ public String indexName(String name) { } public MapperService.SmartNameFieldMappers smartFieldMappers(String name) { - return mapperService.smartName(name); + return indexQueryParser.mapperService.smartName(name); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/XContentIndexQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/XContentIndexQueryParser.java index 5335ca1206eaa..e5e96dc3bff7a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/XContentIndexQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/XContentIndexQueryParser.java @@ -22,6 +22,7 @@ import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.io.FastByteArrayOutputStream; @@ -31,7 +32,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; -import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.engine.IndexEngine; import org.elasticsearch.index.mapper.MapperService; @@ -49,6 +49,7 @@ import java.util.Map; import static org.elasticsearch.common.collect.Lists.*; +import static org.elasticsearch.common.collect.Maps.*; import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; /** @@ -63,28 +64,30 @@ public static final class Defaults { private ThreadLocal> cache = new ThreadLocal>() { @Override protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new QueryParseContext(index, queryParserRegistry, scriptService, mapperService, similarityService, indexCache, indexEngine)); + return new ThreadLocals.CleanableValue(new QueryParseContext(index, XContentIndexQueryParser.this)); } }; private final String name; - private final ScriptService scriptService; + final ScriptService scriptService; - private final MapperService mapperService; + final MapperService mapperService; - private final SimilarityService similarityService; + final SimilarityService similarityService; - private final IndexCache indexCache; + final IndexCache indexCache; - private final IndexEngine indexEngine; + final IndexEngine indexEngine; - private final XContentQueryParserRegistry queryParserRegistry; + private final Map queryParsers; + + private final Map filterParsers; @Inject public XContentIndexQueryParser(Index index, @IndexSettings Settings indexSettings, ScriptService scriptService, MapperService mapperService, IndexCache indexCache, IndexEngine indexEngine, - AnalysisService analysisService, @Nullable SimilarityService similarityService, + @Nullable SimilarityService similarityService, @Nullable Map namedQueryParsers, @Nullable Map namedFilterParsers, @Assisted String name, @Assisted @Nullable Settings settings) { @@ -110,6 +113,14 @@ public static final class Defaults { } } + Map queryParsersMap = newHashMap(); + if (queryParsers != null) { + for (XContentQueryParser queryParser : queryParsers) { + add(queryParsersMap, queryParser); + } + } + this.queryParsers = ImmutableMap.copyOf(queryParsersMap); + List filterParsers = newArrayList(); if (namedFilterParsers != null) { Map filterParserGroups = indexSettings.getGroups(XContentIndexQueryParser.Defaults.FILTER_PREFIX); @@ -124,15 +135,25 @@ public static final class Defaults { } } - this.queryParserRegistry = new XContentQueryParserRegistry(index, indexSettings, analysisService, queryParsers, filterParsers); + Map filterParsersMap = newHashMap(); + if (filterParsers != null) { + for (XContentFilterParser filterParser : filterParsers) { + add(filterParsersMap, filterParser); + } + } + this.filterParsers = ImmutableMap.copyOf(filterParsersMap); } @Override public String name() { return this.name; } - public XContentQueryParserRegistry queryParserRegistry() { - return this.queryParserRegistry; + public XContentQueryParser queryParser(String name) { + return queryParsers.get(name); + } + + public XContentFilterParser filterParser(String name) { + return filterParsers.get(name); } @Override public ParsedQuery parse(QueryBuilder queryBuilder) throws ElasticSearchException { @@ -213,4 +234,16 @@ private ParsedQuery parse(QueryParseContext parseContext, XContentParser parser) Query query = parseContext.parseInnerQuery(); return new ParsedQuery(query, parseContext.copyNamedFilters()); } + + private void add(Map map, XContentFilterParser filterParser) { + for (String name : filterParser.names()) { + map.put(name.intern(), filterParser); + } + } + + private void add(Map map, XContentQueryParser queryParser) { + for (String name : queryParser.names()) { + map.put(name.intern(), queryParser); + } + } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/XContentQueryParserRegistry.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/XContentQueryParserRegistry.java deleted file mode 100644 index d3e52beb9bfbb..0000000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/XContentQueryParserRegistry.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.query.xcontent; - -import org.elasticsearch.common.collect.ImmutableMap; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.analysis.AnalysisService; -import org.elasticsearch.index.settings.IndexSettings; - -import javax.annotation.Nullable; -import java.util.Map; - -import static org.elasticsearch.common.collect.Maps.*; - -/** - * @author kimchy (shay.banon) - */ -public class XContentQueryParserRegistry { - - private final Map queryParsers; - - private final Map filterParsers; - - public XContentQueryParserRegistry(Index index, - @IndexSettings Settings indexSettings, - AnalysisService analysisService, - @Nullable Iterable queryParsers, - @Nullable Iterable filterParsers) { - - Map queryParsersMap = newHashMap(); - // add defaults - add(queryParsersMap, new DisMaxQueryParser(index, indexSettings)); - add(queryParsersMap, new MatchAllQueryParser(index, indexSettings)); - add(queryParsersMap, new QueryStringQueryParser(index, indexSettings, analysisService)); - add(queryParsersMap, new BoolQueryParser(index, indexSettings)); - add(queryParsersMap, new TermQueryParser(index, indexSettings)); - add(queryParsersMap, new FuzzyQueryParser(index, indexSettings)); - add(queryParsersMap, new FieldQueryParser(index, indexSettings, analysisService)); - add(queryParsersMap, new RangeQueryParser(index, indexSettings)); - add(queryParsersMap, new PrefixQueryParser(index, indexSettings)); - add(queryParsersMap, new WildcardQueryParser(index, indexSettings)); - add(queryParsersMap, new FilteredQueryParser(index, indexSettings)); - add(queryParsersMap, new ConstantScoreQueryParser(index, indexSettings)); - add(queryParsersMap, new CustomBoostFactorQueryParser(index, indexSettings)); - add(queryParsersMap, new CustomScoreQueryParser(index, indexSettings)); - add(queryParsersMap, new SpanTermQueryParser(index, indexSettings)); - add(queryParsersMap, new SpanNotQueryParser(index, indexSettings)); - add(queryParsersMap, new SpanFirstQueryParser(index, indexSettings)); - add(queryParsersMap, new SpanNearQueryParser(index, indexSettings)); - add(queryParsersMap, new SpanOrQueryParser(index, indexSettings)); - add(queryParsersMap, new MoreLikeThisQueryParser(index, indexSettings)); - add(queryParsersMap, new MoreLikeThisFieldQueryParser(index, indexSettings)); - add(queryParsersMap, new FuzzyLikeThisQueryParser(index, indexSettings)); - add(queryParsersMap, new FuzzyLikeThisFieldQueryParser(index, indexSettings)); - - // now, copy over the ones provided - if (queryParsers != null) { - for (XContentQueryParser queryParser : queryParsers) { - add(queryParsersMap, queryParser); - } - } - this.queryParsers = ImmutableMap.copyOf(queryParsersMap); - - Map filterParsersMap = newHashMap(); - // add defaults - add(filterParsersMap, new TermFilterParser(index, indexSettings)); - add(filterParsersMap, new TermsFilterParser(index, indexSettings)); - add(filterParsersMap, new RangeFilterParser(index, indexSettings)); - add(filterParsersMap, new PrefixFilterParser(index, indexSettings)); - add(filterParsersMap, new ScriptFilterParser(index, indexSettings)); - add(filterParsersMap, new GeoDistanceFilterParser(index, indexSettings)); - add(filterParsersMap, new GeoBoundingBoxFilterParser(index, indexSettings)); - add(filterParsersMap, new GeoPolygonFilterParser(index, indexSettings)); - add(filterParsersMap, new QueryFilterParser(index, indexSettings)); - add(filterParsersMap, new FQueryFilterParser(index, indexSettings)); - add(filterParsersMap, new BoolFilterParser(index, indexSettings)); - add(filterParsersMap, new AndFilterParser(index, indexSettings)); - add(filterParsersMap, new OrFilterParser(index, indexSettings)); - add(filterParsersMap, new NotFilterParser(index, indexSettings)); - add(filterParsersMap, new MatchAllFilterParser(index, indexSettings)); - - if (filterParsers != null) { - for (XContentFilterParser filterParser : filterParsers) { - add(filterParsersMap, filterParser); - } - } - this.filterParsers = ImmutableMap.copyOf(filterParsersMap); - } - - public XContentQueryParser queryParser(String name) { - return queryParsers.get(name); - } - - public XContentFilterParser filterParser(String name) { - return filterParsers.get(name); - } - - private void add(Map map, XContentFilterParser filterParser) { - for (String name : filterParser.names()) { - map.put(name.intern(), filterParser); - } - } - - private void add(Map map, XContentQueryParser queryParser) { - for (String name : queryParser.names()) { - map.put(name.intern(), queryParser); - } - } -} diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java index 176d85c167905..73805afa39cdc 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java @@ -23,21 +23,32 @@ import org.apache.lucene.search.*; import org.apache.lucene.search.spans.*; import org.apache.lucene.util.NumericUtils; +import org.elasticsearch.common.inject.Injector; +import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.lucene.geo.GeoBoundingBoxFilter; import org.elasticsearch.common.lucene.geo.GeoDistanceFilter; import org.elasticsearch.common.lucene.geo.GeoPolygonFilter; import org.elasticsearch.common.lucene.search.*; import org.elasticsearch.common.lucene.search.function.BoostScoreFunction; import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; -import org.elasticsearch.env.Environment; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.index.Index; -import org.elasticsearch.index.analysis.AnalysisService; -import org.elasticsearch.index.cache.IndexCache; -import org.elasticsearch.index.engine.robin.RobinIndexEngine; +import org.elasticsearch.index.IndexNameModule; +import org.elasticsearch.index.analysis.AnalysisModule; +import org.elasticsearch.index.cache.IndexCacheModule; +import org.elasticsearch.index.engine.IndexEngineModule; import org.elasticsearch.index.mapper.MapperService; +import org.elasticsearch.index.mapper.MapperServiceModule; import org.elasticsearch.index.query.IndexQueryParser; +import org.elasticsearch.index.query.IndexQueryParserModule; +import org.elasticsearch.index.query.IndexQueryParserService; import org.elasticsearch.index.query.ParsedQuery; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.index.settings.IndexSettingsModule; +import org.elasticsearch.index.similarity.SimilarityModule; +import org.elasticsearch.script.ScriptModule; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.io.IOException; @@ -46,7 +57,6 @@ import java.util.Set; import static org.elasticsearch.common.io.Streams.*; -import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.elasticsearch.index.query.xcontent.FilterBuilders.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.hamcrest.MatcherAssert.*; @@ -58,10 +68,36 @@ @Test public class SimpleIndexQueryParserTests { - private final Index index = new Index("test"); + private IndexQueryParserService queryParser; + + @BeforeClass public void setupQueryParser() throws IOException { + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.cache.filter.type", "none") + .build(); + Index index = new Index("test"); + Injector injector = new ModulesBuilder().add( + new SettingsModule(settings), + new ScriptModule(), + new MapperServiceModule(), + new IndexSettingsModule(settings), + new IndexCacheModule(settings), + new AnalysisModule(settings), + new IndexEngineModule(settings), + new SimilarityModule(settings), + new IndexQueryParserModule(settings), + new IndexNameModule(index) + ).createInjector(); + + injector.getInstance(MapperService.class).type("person").parse(copyToBytesFromClasspath("/org/elasticsearch/index/query/xcontent/data.json")); + this.queryParser = injector.getInstance(IndexQueryParserService.class); + } + + private XContentIndexQueryParser queryParser() throws IOException { + return (XContentIndexQueryParser) this.queryParser.defaultIndexQueryParser(); + } @Test public void testQueryStringBuilder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(queryString("test").defaultField("content").phraseSlop(1)).query(); assertThat(parsedQuery, instanceOf(TermQuery.class)); @@ -70,7 +106,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testQueryString() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/query.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(TermQuery.class)); @@ -79,7 +115,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testQueryStringFields1Builder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(queryString("test").field("content").field("name").useDisMax(false)).query(); assertThat(parsedQuery, instanceOf(BooleanQuery.class)); BooleanQuery bQuery = (BooleanQuery) parsedQuery; @@ -89,7 +125,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testQueryStringFields1() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/query-fields1.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(BooleanQuery.class)); @@ -100,7 +136,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testQueryStringFields2Builder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(queryString("test").field("content").field("name").useDisMax(true)).query(); assertThat(parsedQuery, instanceOf(DisjunctionMaxQuery.class)); DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) parsedQuery; @@ -110,7 +146,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testQueryStringFields2() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/query-fields2.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(DisjunctionMaxQuery.class)); @@ -121,7 +157,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testQueryStringFields3Builder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(queryString("test").field("content", 2.2f).field("name").useDisMax(true)).query(); assertThat(parsedQuery, instanceOf(DisjunctionMaxQuery.class)); DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) parsedQuery; @@ -133,7 +169,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testQueryStringFields3() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/query-fields3.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(DisjunctionMaxQuery.class)); @@ -146,7 +182,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testMatchAllBuilder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(matchAllQuery().boost(1.2f)).query(); assertThat(parsedQuery, instanceOf(MatchAllDocsQuery.class)); MatchAllDocsQuery matchAllDocsQuery = (MatchAllDocsQuery) parsedQuery; @@ -154,7 +190,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testMatchAll() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/matchAll.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(MatchAllDocsQuery.class)); @@ -163,7 +199,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testDisMaxBuilder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(disMaxQuery().boost(1.2f).tieBreaker(0.7f).add(termQuery("name.first", "first")).add(termQuery("name.last", "last"))).query(); assertThat(parsedQuery, instanceOf(DisjunctionMaxQuery.class)); DisjunctionMaxQuery disjunctionMaxQuery = (DisjunctionMaxQuery) parsedQuery; @@ -182,7 +218,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testDisMax() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/disMax.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(DisjunctionMaxQuery.class)); @@ -202,7 +238,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testTermQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(termQuery("age", 34).buildAsBytes()).query(); assertThat(parsedQuery, instanceOf(NumericRangeQuery.class)); NumericRangeQuery fieldQuery = (NumericRangeQuery) parsedQuery; @@ -213,7 +249,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testTermQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/term.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(NumericRangeQuery.class)); @@ -225,7 +261,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFuzzyQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(fuzzyQuery("name.first", "sh").buildAsBytes()).query(); assertThat(parsedQuery, instanceOf(FuzzyQuery.class)); FuzzyQuery fuzzyQuery = (FuzzyQuery) parsedQuery; @@ -233,7 +269,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFuzzyQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/fuzzy.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FuzzyQuery.class)); @@ -242,7 +278,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFuzzyQueryWithFieldsBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(fuzzyQuery("name.first", "sh").minSimilarity(0.1f).prefixLength(1).boost(2.0f).buildAsBytes()).query(); assertThat(parsedQuery, instanceOf(FuzzyQuery.class)); FuzzyQuery fuzzyQuery = (FuzzyQuery) parsedQuery; @@ -253,7 +289,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFuzzyQueryWithFields() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/fuzzy-with-fields.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FuzzyQuery.class)); @@ -265,7 +301,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFieldQueryBuilder1() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(fieldQuery("age", 34).buildAsBytes()).query(); assertThat(parsedQuery, instanceOf(NumericRangeQuery.class)); NumericRangeQuery fieldQuery = (NumericRangeQuery) parsedQuery; @@ -276,7 +312,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFieldQuery1() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/field1.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(NumericRangeQuery.class)); @@ -288,7 +324,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFieldQuery2() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/field2.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(BooleanQuery.class)); @@ -301,7 +337,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFieldQuery3() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/field3.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat((double) parsedQuery.getBoost(), closeTo(2.0, 0.01)); @@ -314,7 +350,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testTermWithBoostQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(termQuery("age", 34).boost(2.0f)).query(); assertThat(parsedQuery, instanceOf(NumericRangeQuery.class)); NumericRangeQuery fieldQuery = (NumericRangeQuery) parsedQuery; @@ -326,7 +362,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testTermWithBoostQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/term-with-boost.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(NumericRangeQuery.class)); @@ -339,7 +375,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testPrefixQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(prefixQuery("name.first", "sh")).query(); assertThat(parsedQuery, instanceOf(PrefixQuery.class)); PrefixQuery prefixQuery = (PrefixQuery) parsedQuery; @@ -348,7 +384,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testPrefixQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/prefix.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(PrefixQuery.class)); @@ -358,7 +394,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testPrefixFilteredQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(filtered(termQuery("name.first", "shay"), prefixFilter("name.first", "sh"))).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); FilteredQuery filteredQuery = (FilteredQuery) parsedQuery; @@ -367,7 +403,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testPrefixFilteredQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/prefix-filter.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -377,7 +413,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testPrefixNamedFilteredQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/prefix-filter-named.json"); ParsedQuery parsedQuery = queryParser.parse(query); assertThat(parsedQuery.namedFilters().containsKey("test"), equalTo(true)); @@ -388,7 +424,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testPrefixQueryBoostQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(prefixQuery("name.first", "sh").boost(2.0f)).query(); assertThat(parsedQuery, instanceOf(PrefixQuery.class)); PrefixQuery prefixQuery = (PrefixQuery) parsedQuery; @@ -397,7 +433,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testPrefixQueryBoostQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/prefix-with-boost.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(PrefixQuery.class)); @@ -407,7 +443,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testWildcardQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(wildcardQuery("name.first", "sh*")).query(); assertThat(parsedQuery, instanceOf(WildcardQuery.class)); WildcardQuery wildcardQuery = (WildcardQuery) parsedQuery; @@ -415,7 +451,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testWildcardQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/wildcard.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(WildcardQuery.class)); @@ -424,7 +460,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testRangeQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(rangeQuery("age").from(23).to(54).includeLower(true).includeUpper(false)).query(); // since age is automatically registered in data, we encode it as numeric assertThat(parsedQuery, instanceOf(NumericRangeQuery.class)); @@ -437,7 +473,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testRangeQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/range.json"); Query parsedQuery = queryParser.parse(query).query(); // since age is automatically registered in data, we encode it as numeric @@ -451,7 +487,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testRange2Query() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/range2.json"); Query parsedQuery = queryParser.parse(query).query(); // since age is automatically registered in data, we encode it as numeric @@ -465,7 +501,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testRangeFilteredQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(filtered(termQuery("name.first", "shay"), rangeFilter("age").from(23).to(54).includeLower(true).includeUpper(false))).query(); // since age is automatically registered in data, we encode it as numeric assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -480,7 +516,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testRangeFilteredQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/range-filter.json"); Query parsedQuery = queryParser.parse(query).query(); // since age is automatically registered in data, we encode it as numeric @@ -496,7 +532,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testRangeNamedFilteredQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/range-filter-named.json"); ParsedQuery parsedQuery = queryParser.parse(query); assertThat(parsedQuery.namedFilters().containsKey("test"), equalTo(true)); @@ -512,7 +548,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testBoolFilteredQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/bool-filter.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -523,7 +559,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testAndFilteredQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(filtered(matchAllQuery(), andFilter(termFilter("name.first", "shay1"), termFilter("name.first", "shay4")))).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); FilteredQuery filteredQuery = (FilteredQuery) parsedQuery; @@ -535,7 +571,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testAndFilteredQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/and-filter.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -548,7 +584,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testAndNamedFilteredQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/and-filter-named.json"); ParsedQuery parsedQuery = queryParser.parse(query); assertThat(parsedQuery.namedFilters().containsKey("test"), equalTo(true)); @@ -562,7 +598,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testAndFilteredQuery2() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/and-filter2.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -575,7 +611,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testOrFilteredQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(filtered(matchAllQuery(), orFilter(termFilter("name.first", "shay1"), termFilter("name.first", "shay4")))).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); FilteredQuery filteredQuery = (FilteredQuery) parsedQuery; @@ -587,7 +623,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testOrFilteredQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/or-filter.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -600,7 +636,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testOrFilteredQuery2() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/or-filter2.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -613,7 +649,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testNotFilteredQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(filtered(matchAllQuery(), notFilter(termFilter("name.first", "shay1")))).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); FilteredQuery filteredQuery = (FilteredQuery) parsedQuery; @@ -623,7 +659,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testNotFilteredQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/not-filter.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -634,7 +670,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testBoolQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(boolQuery().must(termQuery("content", "test1")).must(termQuery("content", "test4")).mustNot(termQuery("content", "test2")).should(termQuery("content", "test3"))).query(); assertThat(parsedQuery, instanceOf(BooleanQuery.class)); BooleanQuery booleanQuery = (BooleanQuery) parsedQuery; @@ -657,7 +693,7 @@ public class SimpleIndexQueryParserTests { @Test public void testBoolQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/bool.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(BooleanQuery.class)); @@ -680,7 +716,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFilteredQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(filtered(termQuery("name.first", "shay"), termFilter("name.last", "banon"))).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); FilteredQuery filteredQuery = (FilteredQuery) parsedQuery; @@ -689,7 +725,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFilteredQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/filtered-query.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -699,7 +735,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFilteredQuery2() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/filtered-query2.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -709,7 +745,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFilteredQuery3() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/filtered-query3.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -725,7 +761,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFilteredQuery4() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/filtered-query4.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -738,7 +774,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testTermFilterQuery() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/term-filter.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -750,7 +786,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testTermNamedFilterQuery() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/term-filter-named.json"); ParsedQuery parsedQuery = queryParser.parse(query); assertThat(parsedQuery.namedFilters().containsKey("test"), equalTo(true)); @@ -763,7 +799,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testTermsFilterQueryBuilder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(filtered(termQuery("name.first", "shay"), termsFilter("name.last", "banon", "kimchy"))).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); FilteredQuery filteredQuery = (FilteredQuery) parsedQuery; @@ -778,7 +814,7 @@ public class SimpleIndexQueryParserTests { @Test public void testTermsFilterQuery() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/terms-filter.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -793,7 +829,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testTermsWithNameFilterQuery() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/terms-filter-named.json"); ParsedQuery parsedQuery = queryParser.parse(query); assertThat(parsedQuery.namedFilters().containsKey("test"), equalTo(true)); @@ -809,7 +845,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testConstantScoreQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(constantScoreQuery(termFilter("name.last", "banon"))).query(); assertThat(parsedQuery, instanceOf(ConstantScoreQuery.class)); ConstantScoreQuery constantScoreQuery = (ConstantScoreQuery) parsedQuery; @@ -817,7 +853,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testConstantScoreQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/constantScore-query.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(ConstantScoreQuery.class)); @@ -826,7 +862,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testCustomScoreQuery1() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/custom_score1.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FunctionScoreQuery.class)); @@ -836,7 +872,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testCustomBoostFactorQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(customBoostFactorQuery(termQuery("name.last", "banon")).boostFactor(1.3f)).query(); assertThat(parsedQuery, instanceOf(FunctionScoreQuery.class)); FunctionScoreQuery functionScoreQuery = (FunctionScoreQuery) parsedQuery; @@ -846,7 +882,7 @@ public class SimpleIndexQueryParserTests { @Test public void testCustomBoostFactorQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/custom-boost-factor-query.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FunctionScoreQuery.class)); @@ -856,7 +892,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testSpanTermQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(spanTermQuery("age", 34)).query(); assertThat(parsedQuery, instanceOf(SpanTermQuery.class)); SpanTermQuery termQuery = (SpanTermQuery) parsedQuery; @@ -865,7 +901,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testSpanTermQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/spanTerm.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(SpanTermQuery.class)); @@ -875,7 +911,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testSpanNotQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(spanNotQuery().include(spanTermQuery("age", 34)).exclude(spanTermQuery("age", 35))).query(); assertThat(parsedQuery, instanceOf(SpanNotQuery.class)); SpanNotQuery spanNotQuery = (SpanNotQuery) parsedQuery; @@ -885,7 +921,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testSpanNotQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/spanNot.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(SpanNotQuery.class)); @@ -896,7 +932,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testSpanFirstQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(spanFirstQuery(spanTermQuery("age", 34), 12)).query(); assertThat(parsedQuery, instanceOf(SpanFirstQuery.class)); SpanFirstQuery spanFirstQuery = (SpanFirstQuery) parsedQuery; @@ -906,7 +942,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testSpanFirstQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/spanFirst.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(SpanFirstQuery.class)); @@ -917,7 +953,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testSpanNearQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(spanNearQuery().clause(spanTermQuery("age", 34)).clause(spanTermQuery("age", 35)).clause(spanTermQuery("age", 36)).slop(12).inOrder(false).collectPayloads(false)).query(); assertThat(parsedQuery, instanceOf(SpanNearQuery.class)); SpanNearQuery spanNearQuery = (SpanNearQuery) parsedQuery; @@ -929,7 +965,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testSpanNearQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/spanNear.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(SpanNearQuery.class)); @@ -942,7 +978,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testSpanOrQueryBuilder() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(spanOrQuery().clause(spanTermQuery("age", 34)).clause(spanTermQuery("age", 35)).clause(spanTermQuery("age", 36))).query(); assertThat(parsedQuery, instanceOf(SpanOrQuery.class)); SpanOrQuery spanOrQuery = (SpanOrQuery) parsedQuery; @@ -953,7 +989,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testSpanOrQuery() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/spanOr.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(SpanOrQuery.class)); @@ -965,7 +1001,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testQueryFilterBuilder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(filtered(termQuery("name.first", "shay"), queryFilter(termQuery("name.last", "banon")))).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); FilteredQuery filteredQuery = (FilteredQuery) parsedQuery; @@ -978,7 +1014,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testQueryFilter() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/query-filter.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -992,7 +1028,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testFQueryFilter() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/fquery-filter.json"); ParsedQuery parsedQuery = queryParser.parse(query); assertThat(parsedQuery.namedFilters().containsKey("test"), equalTo(true)); @@ -1007,7 +1043,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testMoreLikeThisBuilder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(moreLikeThisQuery("name.first", "name.last").likeText("something").minTermFreq(1).maxQueryTerms(12)).query(); assertThat(parsedQuery, instanceOf(MoreLikeThisQuery.class)); MoreLikeThisQuery mltQuery = (MoreLikeThisQuery) parsedQuery; @@ -1018,7 +1054,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testMoreLikeThis() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/mlt.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(MoreLikeThisQuery.class)); @@ -1031,14 +1067,14 @@ public class SimpleIndexQueryParserTests { } @Test public void testFuzzyLikeThisBuilder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(fuzzyLikeThisQuery("name.first", "name.last").likeText("something").maxQueryTerms(12)).query(); assertThat(parsedQuery, instanceOf(FuzzyLikeThisQuery.class)); // FuzzyLikeThisQuery fuzzyLikeThisQuery = (FuzzyLikeThisQuery) parsedQuery; } @Test public void testFuzzyLikeThis() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/fuzzyLikeThis.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FuzzyLikeThisQuery.class)); @@ -1046,14 +1082,14 @@ public class SimpleIndexQueryParserTests { } @Test public void testFuzzyLikeFieldThisBuilder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(fuzzyLikeThisFieldQuery("name.first").likeText("something").maxQueryTerms(12)).query(); assertThat(parsedQuery, instanceOf(FuzzyLikeThisQuery.class)); // FuzzyLikeThisQuery fuzzyLikeThisQuery = (FuzzyLikeThisQuery) parsedQuery; } @Test public void testFuzzyLikeThisField() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/fuzzyLikeThisField.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FuzzyLikeThisQuery.class)); @@ -1061,7 +1097,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testMoreLikeThisFieldBuilder() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(moreLikeThisFieldQuery("name.first").likeText("something").minTermFreq(1).maxQueryTerms(12)).query(); assertThat(parsedQuery, instanceOf(MoreLikeThisQuery.class)); MoreLikeThisQuery mltQuery = (MoreLikeThisQuery) parsedQuery; @@ -1072,7 +1108,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testMoreLikeThisField() throws Exception { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/mltField.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(MoreLikeThisQuery.class)); @@ -1084,7 +1120,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoDistanceFilterNamed() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance-named.json"); ParsedQuery parsedQuery = queryParser.parse(query); assertThat(parsedQuery.namedFilters().containsKey("test"), equalTo(true)); @@ -1099,7 +1135,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoDistanceFilter1() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance1.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1113,7 +1149,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoDistanceFilter2() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance2.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1127,7 +1163,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoDistanceFilter3() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance3.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1141,7 +1177,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoDistanceFilter4() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance4.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1155,7 +1191,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoBoundingBoxFilterNamed() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_boundingbox-named.json"); ParsedQuery parsedQuery = queryParser.parse(query); assertThat(parsedQuery.query(), instanceOf(FilteredQuery.class)); @@ -1172,7 +1208,7 @@ public class SimpleIndexQueryParserTests { @Test public void testGeoBoundingBoxFilter1() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_boundingbox1.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1187,7 +1223,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoBoundingBoxFilter2() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_boundingbox2.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1202,7 +1238,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoBoundingBoxFilter3() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_boundingbox3.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1217,7 +1253,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoBoundingBoxFilter4() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_boundingbox4.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1232,7 +1268,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoPolygonNamedFilter() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_polygon-named.json"); ParsedQuery parsedQuery = queryParser.parse(query); assertThat(parsedQuery.namedFilters().containsKey("test"), equalTo(true)); @@ -1251,7 +1287,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoPolygonFilter1() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_polygon1.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1269,7 +1305,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoPolygonFilter2() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_polygon2.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1287,7 +1323,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoPolygonFilter3() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_polygon3.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1305,7 +1341,7 @@ public class SimpleIndexQueryParserTests { } @Test public void testGeoPolygonFilter4() throws IOException { - IndexQueryParser queryParser = newQueryParser(); + IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_polygon4.json"); Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(FilteredQuery.class)); @@ -1321,17 +1357,4 @@ public class SimpleIndexQueryParserTests { assertThat(filter.points()[2].lat, closeTo(20, 0.00001)); assertThat(filter.points()[2].lon, closeTo(-90, 0.00001)); } - - private XContentIndexQueryParser newQueryParser() throws IOException { - return new XContentIndexQueryParser(new Index("test"), EMPTY_SETTINGS, new ScriptService(EMPTY_SETTINGS), - newMapperService(), new IndexCache(index), new RobinIndexEngine(index), new AnalysisService(index), null, null, null, "test", null); - } - - private MapperService newMapperService() throws IOException { - Environment environment = new Environment(); - MapperService mapperService = new MapperService(index, EMPTY_SETTINGS, environment, new AnalysisService(index)); - // init a mapping with data - mapperService.type("person").parse(copyToBytesFromClasspath("/org/elasticsearch/index/query/xcontent/data.json")); - return mapperService; - } } diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/IndexQueryParserModuleTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/IndexQueryParserModuleTests.java index 8bd08da259da6..c349aad7b8398 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/IndexQueryParserModuleTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/IndexQueryParserModuleTests.java @@ -31,7 +31,6 @@ import org.elasticsearch.index.query.IndexQueryParserModule; import org.elasticsearch.index.query.IndexQueryParserService; import org.elasticsearch.index.query.xcontent.XContentIndexQueryParser; -import org.elasticsearch.index.query.xcontent.XContentQueryParserRegistry; import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.index.similarity.SimilarityModule; import org.elasticsearch.script.ScriptModule; @@ -70,14 +69,14 @@ public class IndexQueryParserModuleTests { IndexQueryParserService indexQueryParserService = injector.getInstance(IndexQueryParserService.class); - XContentQueryParserRegistry parserRegistry = ((XContentIndexQueryParser) indexQueryParserService.defaultIndexQueryParser()).queryParserRegistry(); + XContentIndexQueryParser indexQueryParser = ((XContentIndexQueryParser) indexQueryParserService.defaultIndexQueryParser()); - MyJsonQueryParser myJsonQueryParser = (MyJsonQueryParser) parserRegistry.queryParser("my"); + MyJsonQueryParser myJsonQueryParser = (MyJsonQueryParser) indexQueryParser.queryParser("my"); assertThat(myJsonQueryParser.names()[0], equalTo("my")); assertThat(myJsonQueryParser.settings().get("param1"), equalTo("value1")); - MyJsonFilterParser myJsonFilterParser = (MyJsonFilterParser) parserRegistry.filterParser("my"); + MyJsonFilterParser myJsonFilterParser = (MyJsonFilterParser) indexQueryParser.filterParser("my"); assertThat(myJsonFilterParser.names()[0], equalTo("my")); assertThat(myJsonFilterParser.settings().get("param2"), equalTo("value2")); } diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/IndexQueryParserPluginTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/IndexQueryParserPluginTests.java index a7d63f6bb5aa4..03a8a90733391 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/IndexQueryParserPluginTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/IndexQueryParserPluginTests.java @@ -32,7 +32,6 @@ import org.elasticsearch.index.query.IndexQueryParserModule; import org.elasticsearch.index.query.IndexQueryParserService; import org.elasticsearch.index.query.xcontent.XContentIndexQueryParser; -import org.elasticsearch.index.query.xcontent.XContentQueryParserRegistry; import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.index.similarity.SimilarityModule; import org.elasticsearch.script.ScriptModule; @@ -75,13 +74,13 @@ public class IndexQueryParserPluginTests { IndexQueryParserService indexQueryParserService = injector.getInstance(IndexQueryParserService.class); - XContentQueryParserRegistry parserRegistry = ((XContentIndexQueryParser) indexQueryParserService.defaultIndexQueryParser()).queryParserRegistry(); + XContentIndexQueryParser indexQueryParser = ((XContentIndexQueryParser) indexQueryParserService.defaultIndexQueryParser()); - PluginJsonQueryParser myJsonQueryParser = (PluginJsonQueryParser) parserRegistry.queryParser("my"); + PluginJsonQueryParser myJsonQueryParser = (PluginJsonQueryParser) indexQueryParser.queryParser("my"); assertThat(myJsonQueryParser.names()[0], equalTo("my")); - PluginJsonFilterParser myJsonFilterParser = (PluginJsonFilterParser) parserRegistry.filterParser("my"); + PluginJsonFilterParser myJsonFilterParser = (PluginJsonFilterParser) indexQueryParser.filterParser("my"); assertThat(myJsonFilterParser.names()[0], equalTo("my")); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/shard/SimpleIndexShardTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/shard/SimpleIndexShardTests.java deleted file mode 100644 index c382d910bbbd4..0000000000000 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/shard/SimpleIndexShardTests.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.shard; - -import org.elasticsearch.common.Unicode; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.env.Environment; -import org.elasticsearch.index.analysis.AnalysisService; -import org.elasticsearch.index.cache.IndexCache; -import org.elasticsearch.index.deletionpolicy.KeepOnlyLastDeletionPolicy; -import org.elasticsearch.index.deletionpolicy.SnapshotDeletionPolicy; -import org.elasticsearch.index.engine.Engine; -import org.elasticsearch.index.engine.robin.RobinEngine; -import org.elasticsearch.index.engine.robin.RobinIndexEngine; -import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.merge.policy.LogByteSizeMergePolicyProvider; -import org.elasticsearch.index.merge.scheduler.SerialMergeSchedulerProvider; -import org.elasticsearch.index.query.IndexQueryParserService; -import org.elasticsearch.index.shard.service.IndexShard; -import org.elasticsearch.index.shard.service.InternalIndexShard; -import org.elasticsearch.index.similarity.SimilarityService; -import org.elasticsearch.index.store.Store; -import org.elasticsearch.index.store.ram.RamStore; -import org.elasticsearch.index.translog.Translog; -import org.elasticsearch.index.translog.fs.FsTranslog; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.threadpool.scaling.ScalingThreadPool; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.IOException; - -import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; -import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy - */ -public class SimpleIndexShardTests { - - private ThreadPool threadPool; - - private IndexShard indexShard; - - @BeforeMethod public void createIndexShard() throws IOException { - Settings settings = EMPTY_SETTINGS; - Environment environment = new Environment(settings); - ShardId shardId = new ShardId("test", 1); - AnalysisService analysisService = new AnalysisService(shardId.index()); - MapperService mapperService = new MapperService(shardId.index(), settings, environment, analysisService); - IndexQueryParserService queryParserService = new IndexQueryParserService(shardId.index(), mapperService, new IndexCache(shardId.index()), new RobinIndexEngine(shardId.index()), analysisService); - IndexCache indexCache = new IndexCache(shardId.index()); - - SnapshotDeletionPolicy policy = new SnapshotDeletionPolicy(new KeepOnlyLastDeletionPolicy(shardId, settings)); - Store store = new RamStore(shardId, settings, null); - Translog translog = new FsTranslog(shardId, EMPTY_SETTINGS, new File("work/fs-translog"), false); - Engine engine = new RobinEngine(shardId, settings, store, policy, translog, - new LogByteSizeMergePolicyProvider(store), new SerialMergeSchedulerProvider(shardId, settings), - analysisService, new SimilarityService(shardId.index())); - - threadPool = new ScalingThreadPool(); - - indexShard = new InternalIndexShard(shardId, EMPTY_SETTINGS, store, engine, translog, threadPool, mapperService, queryParserService, indexCache).start(); - } - - @AfterMethod public void tearDown() { - indexShard.close(); - threadPool.shutdown(); - } - - @Test public void testSimpleIndexGetDelete() { - String source1 = "{ type1 : { _id : \"1\", name : \"test\", age : 35 } }"; - indexShard.index("type1", "1", Unicode.fromStringAsBytes(source1)); - indexShard.refresh(new Engine.Refresh(true)); - - String sourceFetched = Unicode.fromBytes(indexShard.get("type1", "1")); - - assertThat(sourceFetched, equalTo(source1)); - - assertThat(indexShard.count(0, termQuery("age", 35).buildAsBytes(), null), equalTo(1l)); - assertThat(indexShard.count(0, queryString("name:test").buildAsBytes(), null), equalTo(1l)); - assertThat(indexShard.count(0, queryString("age:35").buildAsBytes(), null), equalTo(1l)); - - indexShard.delete("type1", "1"); - indexShard.refresh(new Engine.Refresh(true)); - - assertThat(indexShard.get("type1", "1"), nullValue()); - - indexShard.index("type1", "1", Unicode.fromStringAsBytes(source1)); - indexShard.refresh(new Engine.Refresh(true)); - sourceFetched = Unicode.fromBytes(indexShard.get("type1", "1")); - assertThat(sourceFetched, equalTo(source1)); - indexShard.deleteByQuery(termQuery("name", "test").buildAsBytes(), null); - indexShard.refresh(new Engine.Refresh(true)); - assertThat(indexShard.get("type1", "1"), nullValue()); - - indexShard.close(); - } -}