diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MapperService.java index cee5b550428..0584fa16472 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -22,6 +22,9 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.Filter; +import org.apache.lucene.search.TermsFilter; import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.collect.UnmodifiableIterator; import org.elasticsearch.common.inject.Inject; @@ -218,6 +221,20 @@ public class MapperService extends AbstractIndexComponent implements Iterable 0) { - if (types.length == 1) { - String type = types[0]; - DocumentMapper docMapper = mapperService.documentMapper(type); - if (docMapper == null) { - throw new TypeMissingException(shardId.index(), type); - } - query = new FilteredQuery(query, indexCache.filter().cache(docMapper.typeFilter())); - } else { - XBooleanFilter booleanFilter = new XBooleanFilter(); - for (String type : types) { - DocumentMapper docMapper = mapperService.documentMapper(type); - if (docMapper == null) { - throw new TypeMissingException(shardId.index(), type); - } - booleanFilter.add(new FilterClause(indexCache.filter().cache(docMapper.typeFilter()), BooleanClause.Occur.SHOULD)); - } - query = new FilteredQuery(query, booleanFilter); - } + query = new FilteredQuery(query, indexCache.filter().cache(mapperService.typesFilter(types))); } return query; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/FacetsPhase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/FacetsPhase.java index 4dfad884d4e..0913af8dc49 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/FacetsPhase.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/FacetsPhase.java @@ -19,8 +19,6 @@ package org.elasticsearch.search.facet; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.FilterClause; import org.apache.lucene.search.FilteredQuery; import org.apache.lucene.search.Query; import org.elasticsearch.ElasticSearchException; @@ -28,8 +26,6 @@ import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.collect.Lists; import org.elasticsearch.common.lucene.search.NoopCollector; import org.elasticsearch.common.lucene.search.Queries; -import org.elasticsearch.common.lucene.search.XBooleanFilter; -import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchPhase; import org.elasticsearch.search.facet.collector.FacetCollector; @@ -66,18 +62,7 @@ public class FacetsPhase implements SearchPhase { if (context.searcher().globalCollectors() != null) { Query query = Queries.MATCH_ALL_QUERY; if (context.types().length > 0) { - if (context.types().length == 1) { - String type = context.types()[0]; - DocumentMapper docMapper = context.mapperService().documentMapper(type); - query = new FilteredQuery(query, context.filterCache().cache(docMapper.typeFilter())); - } else { - XBooleanFilter booleanFilter = new XBooleanFilter(); - for (String type : context.types()) { - DocumentMapper docMapper = context.mapperService().documentMapper(type); - booleanFilter.add(new FilterClause(context.filterCache().cache(docMapper.typeFilter()), BooleanClause.Occur.SHOULD)); - } - query = new FilteredQuery(query, booleanFilter); - } + query = new FilteredQuery(query, context.filterCache().cache(context.mapperService().typesFilter(context.types()))); } context.searcher().useGlobalCollectors(true); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java index fc213ed6ed3..be7a4b2b5f9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java @@ -19,16 +19,15 @@ package org.elasticsearch.search.query; -import org.apache.lucene.search.*; +import org.apache.lucene.search.FilteredQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.SortField; +import org.apache.lucene.search.TopDocs; import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.lucene.search.XBooleanFilter; import org.elasticsearch.common.lucene.search.function.BoostScoreFunction; import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.query.ParsedQuery; -import org.elasticsearch.indices.TypeMissingException; import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchParseException; import org.elasticsearch.search.SearchPhase; @@ -81,24 +80,7 @@ public class QueryPhase implements SearchPhase { Query query = searchContext.query(); if (searchContext.types().length > 0) { - if (searchContext.types().length == 1) { - String type = searchContext.types()[0]; - DocumentMapper docMapper = searchContext.mapperService().documentMapper(type); - if (docMapper == null) { - throw new TypeMissingException(new Index(searchContext.shardTarget().index()), type); - } - query = new FilteredQuery(query, searchContext.filterCache().cache(docMapper.typeFilter())); - } else { - XBooleanFilter booleanFilter = new XBooleanFilter(); - for (String type : searchContext.types()) { - DocumentMapper docMapper = searchContext.mapperService().documentMapper(type); - if (docMapper == null) { - throw new TypeMissingException(new Index(searchContext.shardTarget().index()), type); - } - booleanFilter.add(new FilterClause(searchContext.filterCache().cache(docMapper.typeFilter()), BooleanClause.Occur.SHOULD)); - } - query = new FilteredQuery(query, booleanFilter); - } + query = new FilteredQuery(query, searchContext.filterCache().cache(searchContext.mapperService().typesFilter(searchContext.types()))); } TopDocs topDocs;