simplify check if there is explicit type name and doc mapper in the field to be used

This commit is contained in:
Shay Banon 2012-01-30 02:19:31 +02:00
parent f6deb45970
commit 06da379f50
42 changed files with 49 additions and 47 deletions

View File

@ -131,7 +131,7 @@ public class MapperQueryParser extends QueryParser {
if (currentMapper != null) {
Query query = null;
if (currentMapper.useFieldQueryWithQueryString()) {
if (fieldMappers.hasDocMapper()) {
if (fieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{fieldMappers.docMapper().type()});
try {
query = currentMapper.fieldQuery(queryText, parseContext);
@ -202,7 +202,7 @@ public class MapperQueryParser extends QueryParser {
if (currentMapper != null) {
Query query = null;
if (currentMapper.useFieldQueryWithQueryString()) {
if (fieldMappers.hasDocMapper()) {
if (fieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{fieldMappers.docMapper().type()});
try {
query = currentMapper.prefixQuery(termStr, multiTermRewriteMethod, parseContext);

View File

@ -742,6 +742,10 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
return this.explicitTypeInName;
}
public boolean explicitTypeInNameWithDocMapper() {
return explicitTypeInName && docMapper != null;
}
/**
* The best effort search analyzer associated with this field.
*/

View File

@ -84,7 +84,7 @@ public class PrefixFilterParser implements FilterParser {
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
if (smartNameFieldMappers.hasDocMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try {
filter = smartNameFieldMappers.mapper().prefixFilter(value, parseContext);

View File

@ -96,7 +96,7 @@ public class PrefixQueryParser implements QueryParser {
Query query = null;
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
if (smartNameFieldMappers.hasDocMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try {
query = smartNameFieldMappers.mapper().prefixQuery(value, method, parseContext);

View File

@ -87,7 +87,7 @@ public class TermFilterParser implements FilterParser {
Filter filter = null;
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
if (smartNameFieldMappers.hasDocMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try {
filter = smartNameFieldMappers.mapper().fieldFilter(value, parseContext);

View File

@ -90,7 +90,7 @@ public class TermQueryParser implements QueryParser {
Query query = null;
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
if (smartNameFieldMappers.hasDocMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try {
query = smartNameFieldMappers.mapper().fieldQuery(value, parseContext);

View File

@ -107,7 +107,7 @@ public class TermsFilterParser implements FilterParser {
fieldName = fieldMapper.names().indexName();
}
// if we have a doc mapper, its explicit type, mark it
if (smartNameFieldMappers.hasDocMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
}
}
@ -204,7 +204,7 @@ public class TermsFilterParser implements FilterParser {
}
return filter;
} finally {
if (smartNameFieldMappers != null && smartNameFieldMappers.hasDocMapper()) {
if (smartNameFieldMappers != null && smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
QueryParseContext.setTypes(previousTypes);
}
}

View File

@ -100,7 +100,7 @@ public class TermsQueryParser implements QueryParser {
String[] previousTypes = null;
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
mapper = smartNameFieldMappers.mapper();
if (smartNameFieldMappers.hasDocMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
}
}
@ -120,7 +120,7 @@ public class TermsQueryParser implements QueryParser {
}
return wrapSmartNameQuery(optimizeQuery(fixNegativeQueryIfNeeded(query)), smartNameFieldMappers, parseContext);
} finally {
if (smartNameFieldMappers != null && smartNameFieldMappers.hasDocMapper()) {
if (smartNameFieldMappers != null && smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
QueryParseContext.setTypes(previousTypes);
}
}

View File

@ -83,7 +83,7 @@ public final class QueryParsers {
if (smartFieldMappers == null) {
return query;
}
if (!smartFieldMappers.hasDocMapper() || !smartFieldMappers.explicitTypeInName()) {
if (!smartFieldMappers.explicitTypeInNameWithDocMapper()) {
return query;
}
DocumentMapper docMapper = smartFieldMappers.docMapper();
@ -95,7 +95,7 @@ public final class QueryParsers {
if (smartFieldMappers == null) {
return filter;
}
if (!smartFieldMappers.hasDocMapper() || !smartFieldMappers.explicitTypeInName()) {
if (!smartFieldMappers.explicitTypeInNameWithDocMapper()) {
return filter;
}
DocumentMapper docMapper = smartFieldMappers.docMapper();

View File

@ -112,7 +112,7 @@ public class TextQueryParser {
}
if (mapper != null && mapper.useFieldQueryWithQueryString()) {
if (smartNameFieldMappers.hasDocMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try {
return wrapSmartNameQuery(mapper.fieldQuery(text, parseContext), smartNameFieldMappers, parseContext);

View File

@ -64,7 +64,7 @@ public class CountDateHistogramFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -66,7 +66,7 @@ public class ValueDateHistogramFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -69,7 +69,7 @@ public class ValueScriptDateHistogramFacetCollector extends AbstractFacetCollect
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -78,7 +78,7 @@ public class GeoDistanceFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -59,7 +59,7 @@ public class BoundedCountHistogramFacetCollector extends AbstractFacetCollector
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -67,7 +67,7 @@ public class BoundedValueHistogramFacetCollector extends AbstractFacetCollector
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -67,7 +67,7 @@ public class BoundedValueScriptHistogramFacetCollector extends AbstractFacetColl
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -38,8 +38,6 @@ import java.io.IOException;
/**
* A histogram facet collector that uses the same field as the key as well as the
* value.
*
*
*/
public class CountHistogramFacetCollector extends AbstractFacetCollector {
@ -66,7 +64,7 @@ public class CountHistogramFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -64,7 +64,7 @@ public class FullHistogramFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -68,7 +68,7 @@ public class ValueHistogramFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -69,7 +69,7 @@ public class ValueScriptHistogramFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -62,7 +62,7 @@ public class KeyValueRangeFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -59,7 +59,7 @@ public class RangeFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -56,7 +56,7 @@ public class StatisticalFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -83,7 +83,7 @@ public class TermsByteFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -86,7 +86,7 @@ public class TermsByteOrdinalsFacetCollector extends AbstractFacetCollector {
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -82,7 +82,7 @@ public class TermsDoubleFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms double facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -85,7 +85,7 @@ public class TermsDoubleOrdinalsFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms double facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -82,7 +82,7 @@ public class TermsFloatFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms float facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -85,7 +85,7 @@ public class TermsFloatOrdinalsFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms float facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -82,7 +82,7 @@ public class TermsIntFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms int facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -85,7 +85,7 @@ public class TermsIntOrdinalsFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms int facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -79,7 +79,7 @@ public class TermsIpFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms long facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -85,7 +85,7 @@ public class TermsIpOrdinalsFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms long facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -89,7 +89,7 @@ public class TermsLongFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms long facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -85,7 +85,7 @@ public class TermsLongOrdinalsFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms long facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -82,7 +82,7 @@ public class TermsShortFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms short facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -85,7 +85,7 @@ public class TermsShortOrdinalsFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms short facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -88,7 +88,7 @@ public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
throw new ElasticSearchIllegalArgumentException("Field [" + fieldName + "] doesn't have a type, can't run terms long facet collector on it");
}
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -80,7 +80,7 @@ public class TermsStatsDoubleFacetCollector extends AbstractFacetCollector {
this.keyFieldDataType = FieldDataType.DefaultTypes.STRING;
} else {
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -81,7 +81,7 @@ public class TermsStatsLongFacetCollector extends AbstractFacetCollector {
this.keyFieldDataType = FieldDataType.DefaultTypes.STRING;
} else {
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}

View File

@ -81,7 +81,7 @@ public class TermsStatsStringFacetCollector extends AbstractFacetCollector {
this.keyFieldDataType = FieldDataType.DefaultTypes.STRING;
} else {
// add type filter if there is exact doc mapper associated with it
if (smartMappers.hasDocMapper() && smartMappers.explicitTypeInName()) {
if (smartMappers.explicitTypeInNameWithDocMapper()) {
setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter()));
}