Permalink
Browse files

When searching against an index/type, use the type information to der…

…ive different search aspects, closes #1391.
  • Loading branch information...
1 parent 325064c commit 6a146e7ad0b939c56ceb8759dba34139de5e687b @kimchy kimchy committed Oct 17, 2011
Showing with 478 additions and 379 deletions.
  1. +34 −37 modules/elasticsearch/src/main/java/org/apache/lucene/queryParser/MapperQueryParser.java
  2. +134 −33 modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MapperService.java
  3. +1 −1 modules/elasticsearch/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryParser.java
  4. +4 −5 modules/elasticsearch/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxFilterParser.java
  5. +4 −4 modules/elasticsearch/src/main/java/org/elasticsearch/index/query/GeoDistanceFilterParser.java
  6. +4 −4 modules/elasticsearch/src/main/java/org/elasticsearch/index/query/GeoDistanceRangeFilterParser.java
  7. +4 −4 modules/elasticsearch/src/main/java/org/elasticsearch/index/query/GeoPolygonFilterParser.java
  8. +3 −3 modules/elasticsearch/src/main/java/org/elasticsearch/index/query/MoreLikeThisFieldQueryParser.java
  9. +5 −2 modules/elasticsearch/src/main/java/org/elasticsearch/index/query/QueryParseContext.java
  10. +2 −2 modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java
  11. +2 −2 modules/elasticsearch/src/main/java/org/elasticsearch/index/search/TextQueryParser.java
  12. +2 −2 .../src/main/java/org/elasticsearch/search/facet/datehistogram/CountDateHistogramFacetCollector.java
  13. +1 −1 ...earch/src/main/java/org/elasticsearch/search/facet/datehistogram/DateHistogramFacetProcessor.java
  14. +3 −3 .../src/main/java/org/elasticsearch/search/facet/datehistogram/ValueDateHistogramFacetCollector.java
  15. +2 −2 ...ain/java/org/elasticsearch/search/facet/datehistogram/ValueScriptDateHistogramFacetCollector.java
  16. +2 −2 ...ticsearch/src/main/java/org/elasticsearch/search/facet/geodistance/GeoDistanceFacetCollector.java
  17. +5 −5 ...arch/src/main/java/org/elasticsearch/search/facet/geodistance/ValueGeoDistanceFacetCollector.java
  18. +6 −2 ...elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/HistogramFacetProcessor.java
  19. +2 −2 ...in/java/org/elasticsearch/search/facet/histogram/bounded/BoundedCountHistogramFacetCollector.java
  20. +6 −7 ...in/java/org/elasticsearch/search/facet/histogram/bounded/BoundedValueHistogramFacetCollector.java
  21. +2 −2 ...a/org/elasticsearch/search/facet/histogram/bounded/BoundedValueScriptHistogramFacetCollector.java
  22. +2 −2 ...rc/main/java/org/elasticsearch/search/facet/histogram/unbounded/CountHistogramFacetCollector.java
  23. +2 −2 ...src/main/java/org/elasticsearch/search/facet/histogram/unbounded/FullHistogramFacetCollector.java
  24. +6 −7 ...rc/main/java/org/elasticsearch/search/facet/histogram/unbounded/ValueHistogramFacetCollector.java
  25. +2 −2 ...n/java/org/elasticsearch/search/facet/histogram/unbounded/ValueScriptHistogramFacetCollector.java
  26. +6 −7 ...elasticsearch/src/main/java/org/elasticsearch/search/facet/range/KeyValueRangeFacetCollector.java
  27. +2 −2 modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/range/RangeFacetCollector.java
  28. +1 −1 modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/range/RangeFacetProcessor.java
  29. +2 −2 ...ticsearch/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFacetCollector.java
  30. +1 −1 ...rch/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFieldsFacetCollector.java
  31. +1 −1 modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/terms/TermsFacetProcessor.java
  32. +11 −11 ...asticsearch/src/main/java/org/elasticsearch/search/facet/terms/bytes/TermsByteFacetCollector.java
  33. +11 −11 ...rch/src/main/java/org/elasticsearch/search/facet/terms/bytes/TermsByteOrdinalsFacetCollector.java
  34. +11 −12 ...csearch/src/main/java/org/elasticsearch/search/facet/terms/doubles/TermsDoubleFacetCollector.java
  35. +11 −12 ...src/main/java/org/elasticsearch/search/facet/terms/doubles/TermsDoubleOrdinalsFacetCollector.java
  36. +11 −12 ...ticsearch/src/main/java/org/elasticsearch/search/facet/terms/floats/TermsFloatFacetCollector.java
  37. +11 −12 ...h/src/main/java/org/elasticsearch/search/facet/terms/floats/TermsFloatOrdinalsFacetCollector.java
  38. +11 −12 ...elasticsearch/src/main/java/org/elasticsearch/search/facet/terms/ints/TermsIntFacetCollector.java
  39. +11 −12 ...earch/src/main/java/org/elasticsearch/search/facet/terms/ints/TermsIntOrdinalsFacetCollector.java
  40. +11 −12 ...es/elasticsearch/src/main/java/org/elasticsearch/search/facet/terms/ip/TermsIpFacetCollector.java
  41. +11 −12 ...icsearch/src/main/java/org/elasticsearch/search/facet/terms/ip/TermsIpOrdinalsFacetCollector.java
  42. +11 −12 ...asticsearch/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetCollector.java
  43. +11 −12 ...rch/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongOrdinalsFacetCollector.java
  44. +11 −12 ...ticsearch/src/main/java/org/elasticsearch/search/facet/terms/shorts/TermsShortFacetCollector.java
  45. +11 −12 ...h/src/main/java/org/elasticsearch/search/facet/terms/shorts/TermsShortOrdinalsFacetCollector.java
  46. +1 −1 ...h/src/main/java/org/elasticsearch/search/facet/terms/strings/FieldsTermsStringFacetCollector.java
  47. +1 −1 ...csearch/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringFacetCollector.java
  48. +11 −12 ...src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringOrdinalsFacetCollector.java
  49. +1 −1 ...asticsearch/src/main/java/org/elasticsearch/search/facet/termsstats/TermsStatsFacetProcessor.java
  50. +6 −7 ...c/main/java/org/elasticsearch/search/facet/termsstats/doubles/TermsStatsDoubleFacetCollector.java
  51. +6 −7 ...h/src/main/java/org/elasticsearch/search/facet/termsstats/longs/TermsStatsLongFacetCollector.java
  52. +6 −7 ...c/main/java/org/elasticsearch/search/facet/termsstats/strings/TermsStatsStringFacetCollector.java
  53. +1 −1 modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java
  54. +14 −0 modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java
  55. +1 −1 modules/elasticsearch/src/main/java/org/elasticsearch/search/sort/SortParseElement.java
  56. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_boundingbox-named.json
  57. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_boundingbox1.json
  58. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_boundingbox2.json
  59. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_boundingbox3.json
  60. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_boundingbox4.json
  61. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance-named.json
  62. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance1.json
  63. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance10.json
  64. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance11.json
  65. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance12.json
  66. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance2.json
  67. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance3.json
  68. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance4.json
  69. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance5.json
  70. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance6.json
  71. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance7.json
  72. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance8.json
  73. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_distance9.json
  74. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_polygon-named.json
  75. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_polygon1.json
  76. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_polygon2.json
  77. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_polygon3.json
  78. +1 −1 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/geo_polygon4.json
@@ -19,6 +19,7 @@
package org.apache.lucene.queryParser;
+import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.index.Term;
@@ -30,7 +31,6 @@
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.index.mapper.FieldMapper;
-import org.elasticsearch.index.mapper.FieldMappers;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.internal.AllFieldMapper;
import org.elasticsearch.index.query.QueryParseContext;
@@ -115,9 +115,11 @@ public void reset(QueryParserSettings settings) {
return fieldQueryExtension.query(parseContext, queryText);
}
currentMapper = null;
- if (parseContext.mapperService() != null) {
- MapperService.SmartNameFieldMappers fieldMappers = parseContext.mapperService().smartName(field);
+ Analyzer oldAnalyzer = analyzer;
+ try {
+ MapperService.SmartNameFieldMappers fieldMappers = parseContext.smartFieldMappers(field);
if (fieldMappers != null) {
+ analyzer = fieldMappers.searchAnalyzer();
currentMapper = fieldMappers.fieldMappers().mapper();
if (currentMapper != null) {
Query query = null;
@@ -130,8 +132,10 @@ public void reset(QueryParserSettings settings) {
return wrapSmartNameQuery(query, fieldMappers, parseContext);
}
}
+ return super.getFieldQuery(field, queryText, quoted);
+ } finally {
+ analyzer = oldAnalyzer;
}
- return super.getFieldQuery(field, queryText, quoted);
}
@Override protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {
@@ -142,29 +146,25 @@ public void reset(QueryParserSettings settings) {
part2 = null;
}
currentMapper = null;
- if (parseContext.mapperService() != null) {
- MapperService.SmartNameFieldMappers fieldMappers = parseContext.mapperService().smartName(field);
- if (fieldMappers != null) {
- currentMapper = fieldMappers.fieldMappers().mapper();
- if (currentMapper != null) {
- Query rangeQuery = currentMapper.rangeQuery(part1, part2, inclusive, inclusive);
- return wrapSmartNameQuery(rangeQuery, fieldMappers, parseContext);
- }
+ MapperService.SmartNameFieldMappers fieldMappers = parseContext.smartFieldMappers(field);
+ if (fieldMappers != null) {
+ currentMapper = fieldMappers.fieldMappers().mapper();
+ if (currentMapper != null) {
+ Query rangeQuery = currentMapper.rangeQuery(part1, part2, inclusive, inclusive);
+ return wrapSmartNameQuery(rangeQuery, fieldMappers, parseContext);
}
}
return newRangeQuery(field, part1, part2, inclusive);
}
@Override protected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException {
currentMapper = null;
- if (parseContext.mapperService() != null) {
- MapperService.SmartNameFieldMappers fieldMappers = parseContext.mapperService().smartName(field);
- if (fieldMappers != null) {
- currentMapper = fieldMappers.fieldMappers().mapper();
- if (currentMapper != null) {
- Query fuzzyQuery = currentMapper.fuzzyQuery(termStr, minSimilarity, fuzzyPrefixLength, FuzzyQuery.defaultMaxExpansions);
- return wrapSmartNameQuery(fuzzyQuery, fieldMappers, parseContext);
- }
+ MapperService.SmartNameFieldMappers fieldMappers = parseContext.smartFieldMappers(field);
+ if (fieldMappers != null) {
+ currentMapper = fieldMappers.fieldMappers().mapper();
+ if (currentMapper != null) {
+ Query fuzzyQuery = currentMapper.fuzzyQuery(termStr, minSimilarity, fuzzyPrefixLength, FuzzyQuery.defaultMaxExpansions);
+ return wrapSmartNameQuery(fuzzyQuery, fieldMappers, parseContext);
}
}
return super.getFuzzyQuery(field, termStr, minSimilarity);
@@ -173,17 +173,21 @@ public void reset(QueryParserSettings settings) {
@Override protected Query getPrefixQuery(String field, String termStr) throws ParseException {
String indexedNameField = field;
currentMapper = null;
- if (parseContext.mapperService() != null) {
- MapperService.SmartNameFieldMappers fieldMappers = parseContext.mapperService().smartName(field);
+ Analyzer oldAnalyzer = analyzer;
+ try {
+ MapperService.SmartNameFieldMappers fieldMappers = parseContext.smartFieldMappers(field);
if (fieldMappers != null) {
+ analyzer = fieldMappers.searchAnalyzer();
currentMapper = fieldMappers.fieldMappers().mapper();
if (currentMapper != null) {
indexedNameField = currentMapper.names().indexName();
}
return wrapSmartNameQuery(getPossiblyAnalyzedPrefixQuery(indexedNameField, termStr), fieldMappers, parseContext);
}
+ return getPossiblyAnalyzedPrefixQuery(indexedNameField, termStr);
+ } finally {
+ analyzer = oldAnalyzer;
}
- return getPossiblyAnalyzedPrefixQuery(indexedNameField, termStr);
}
private Query getPossiblyAnalyzedPrefixQuery(String field, String termStr) throws ParseException {
@@ -234,17 +238,21 @@ private Query getPossiblyAnalyzedPrefixQuery(String field, String termStr) throw
}
String indexedNameField = field;
currentMapper = null;
- if (parseContext.mapperService() != null) {
- MapperService.SmartNameFieldMappers fieldMappers = parseContext.mapperService().smartName(field);
+ Analyzer oldAnalyzer = analyzer;
+ try {
+ MapperService.SmartNameFieldMappers fieldMappers = parseContext.smartFieldMappers(field);
if (fieldMappers != null) {
+ analyzer = fieldMappers.searchAnalyzer();
currentMapper = fieldMappers.fieldMappers().mapper();
if (currentMapper != null) {
indexedNameField = currentMapper.names().indexName();
}
return wrapSmartNameQuery(getPossiblyAnalyzedWildcardQuery(indexedNameField, termStr), fieldMappers, parseContext);
}
+ return getPossiblyAnalyzedWildcardQuery(indexedNameField, termStr);
+ } finally {
+ analyzer = oldAnalyzer;
}
- return getPossiblyAnalyzedWildcardQuery(indexedNameField, termStr);
}
private Query getPossiblyAnalyzedWildcardQuery(String field, String termStr) throws ParseException {
@@ -318,15 +326,4 @@ private Query getPossiblyAnalyzedWildcardQuery(String field, String termStr) thr
}
return optimizeQuery(fixNegativeQueryIfNeeded(q));
}
-
- protected FieldMapper fieldMapper(String smartName) {
- if (parseContext.mapperService() == null) {
- return null;
- }
- FieldMappers fieldMappers = parseContext.mapperService().smartNameFieldMappers(smartName);
- if (fieldMappers == null) {
- return null;
- }
- return fieldMappers.mapper();
- }
}
@@ -408,6 +408,44 @@ public ObjectMappers objectMapper(String path) {
return objectMappers.get(path);
}
+ public Set<String> simpleMatchToIndexNames(String pattern) {
+ int dotIndex = pattern.indexOf('.');
+ if (dotIndex != -1) {
+ String possibleType = pattern.substring(0, dotIndex);
+ DocumentMapper possibleDocMapper = mappers.get(possibleType);
+ if (possibleDocMapper != null) {
+ Set<String> typedFields = Sets.newHashSet();
+ for (String indexName : possibleDocMapper.mappers().simpleMatchToIndexNames(pattern)) {
+ typedFields.add(possibleType + "." + indexName);
+ }
+ return typedFields;
+ }
+ }
+ Set<String> fields = Sets.newHashSet();
+ for (Map.Entry<String, FieldMappers> entry : fullNameFieldMappers.entrySet()) {
+ if (Regex.simpleMatch(pattern, entry.getKey())) {
+ for (FieldMapper mapper : entry.getValue()) {
+ fields.add(mapper.names().indexName());
+ }
+ }
+ }
+ for (Map.Entry<String, FieldMappers> entry : indexNameFieldMappers.entrySet()) {
+ if (Regex.simpleMatch(pattern, entry.getKey())) {
+ for (FieldMapper mapper : entry.getValue()) {
+ fields.add(mapper.names().indexName());
+ }
+ }
+ }
+ for (Map.Entry<String, FieldMappers> entry : nameFieldMappers.entrySet()) {
+ if (Regex.simpleMatch(pattern, entry.getKey())) {
+ for (FieldMapper mapper : entry.getValue()) {
+ fields.add(mapper.names().indexName());
+ }
+ }
+ }
+ return fields;
+ }
+
public SmartNameObjectMapper smartNameObjectMapper(String smartName) {
int dotIndex = smartName.indexOf('.');
if (dotIndex != -1) {
@@ -440,42 +478,45 @@ public FieldMapper smartNameFieldMapper(String smartName) {
return null;
}
- public Set<String> simpleMatchToIndexNames(String pattern) {
- int dotIndex = pattern.indexOf('.');
- if (dotIndex != -1) {
- String possibleType = pattern.substring(0, dotIndex);
- DocumentMapper possibleDocMapper = mappers.get(possibleType);
- if (possibleDocMapper != null) {
- Set<String> typedFields = Sets.newHashSet();
- for (String indexName : possibleDocMapper.mappers().simpleMatchToIndexNames(pattern)) {
- typedFields.add(possibleType + "." + indexName);
- }
- return typedFields;
- }
+ public FieldMapper smartNameFieldMapper(String smartName, @Nullable String[] types) {
+ FieldMappers fieldMappers = smartNameFieldMappers(smartName, types);
+ if (fieldMappers != null) {
+ return fieldMappers.mapper();
}
- Set<String> fields = Sets.newHashSet();
- for (Map.Entry<String, FieldMappers> entry : fullNameFieldMappers.entrySet()) {
- if (Regex.simpleMatch(pattern, entry.getKey())) {
- for (FieldMapper mapper : entry.getValue()) {
- fields.add(mapper.names().indexName());
- }
- }
+ return null;
+ }
+
+ public FieldMappers smartNameFieldMappers(String smartName, @Nullable String[] types) {
+ if (types == null || types.length == 0) {
+ return smartNameFieldMappers(smartName);
}
- for (Map.Entry<String, FieldMappers> entry : indexNameFieldMappers.entrySet()) {
- if (Regex.simpleMatch(pattern, entry.getKey())) {
- for (FieldMapper mapper : entry.getValue()) {
- fields.add(mapper.names().indexName());
+ for (String type : types) {
+ DocumentMapper documentMapper = mappers.get(type);
+ // we found a mapper
+ if (documentMapper != null) {
+ // see if we find a field for it
+ FieldMappers mappers = documentMapper.mappers().smartName(smartName);
+ if (mappers != null) {
+ return mappers;
}
}
}
- for (Map.Entry<String, FieldMappers> entry : nameFieldMappers.entrySet()) {
- if (Regex.simpleMatch(pattern, entry.getKey())) {
- for (FieldMapper mapper : entry.getValue()) {
- fields.add(mapper.names().indexName());
+ // did not find explicit field in the type provided, see if its prefixed with type
+ int dotIndex = smartName.indexOf('.');
+ if (dotIndex != -1) {
+ String possibleType = smartName.substring(0, dotIndex);
+ DocumentMapper possibleDocMapper = mappers.get(possibleType);
+ if (possibleDocMapper != null) {
+ String possibleName = smartName.substring(dotIndex + 1);
+ FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
+ if (mappers != null) {
+ return mappers;
}
}
}
- return fields;
+ // we did not find the field mapping in any of the types, so don't go and try to find
+ // it in other types...
+ return null;
}
/**
@@ -505,6 +546,39 @@ public FieldMappers smartNameFieldMappers(String smartName) {
return name(smartName);
}
+ public SmartNameFieldMappers smartName(String smartName, @Nullable String[] types) {
+ if (types == null || types.length == 0) {
+ return smartName(smartName);
+ }
+ for (String type : types) {
+ DocumentMapper documentMapper = mappers.get(type);
+ // we found a mapper
+ if (documentMapper != null) {
+ // see if we find a field for it
+ FieldMappers mappers = documentMapper.mappers().smartName(smartName);
+ if (mappers != null) {
+ return new SmartNameFieldMappers(this, mappers, documentMapper, false);
+ }
+ }
+ }
+ // did not find explicit field in the type provided, see if its prefixed with type
+ int dotIndex = smartName.indexOf('.');
+ if (dotIndex != -1) {
+ String possibleType = smartName.substring(0, dotIndex);
+ DocumentMapper possibleDocMapper = mappers.get(possibleType);
+ if (possibleDocMapper != null) {
+ String possibleName = smartName.substring(dotIndex + 1);
+ FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
+ if (mappers != null) {
+ return new SmartNameFieldMappers(this, mappers, possibleDocMapper, true);
+ }
+ }
+ }
+ // we did not find the field mapping in any of the types, so don't go and try to find
+ // it in other types...
+ return null;
+ }
+
/**
* Returns smart field mappers based on a smart name. A smart name is one that can optioannly be prefixed
* with a type (and then a '.'). If it is, then the {@link MapperService.SmartNameFieldMappers}
@@ -526,21 +600,21 @@ public SmartNameFieldMappers smartName(String smartName) {
String possibleName = smartName.substring(dotIndex + 1);
FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
if (mappers != null) {
- return new SmartNameFieldMappers(mappers, possibleDocMapper);
+ return new SmartNameFieldMappers(this, mappers, possibleDocMapper, true);
}
}
}
FieldMappers fieldMappers = fullName(smartName);
if (fieldMappers != null) {
- return new SmartNameFieldMappers(fieldMappers, null);
+ return new SmartNameFieldMappers(this, fieldMappers, null, false);
}
fieldMappers = indexName(smartName);
if (fieldMappers != null) {
- return new SmartNameFieldMappers(fieldMappers, null);
+ return new SmartNameFieldMappers(this, fieldMappers, null, false);
}
fieldMappers = name(smartName);
if (fieldMappers != null) {
- return new SmartNameFieldMappers(fieldMappers, null);
+ return new SmartNameFieldMappers(this, fieldMappers, null, false);
}
return null;
}
@@ -576,12 +650,16 @@ public DocumentMapper docMapper() {
}
public static class SmartNameFieldMappers {
+ private final MapperService mapperService;
private final FieldMappers fieldMappers;
private final DocumentMapper docMapper;
+ private final boolean explicitTypeInName;
- public SmartNameFieldMappers(FieldMappers fieldMappers, @Nullable DocumentMapper docMapper) {
+ public SmartNameFieldMappers(MapperService mapperService, FieldMappers fieldMappers, @Nullable DocumentMapper docMapper, boolean explicitTypeInName) {
+ this.mapperService = mapperService;
this.fieldMappers = fieldMappers;
this.docMapper = docMapper;
+ this.explicitTypeInName = explicitTypeInName;
}
/**
@@ -620,6 +698,29 @@ public boolean hasDocMapper() {
public DocumentMapper docMapper() {
return docMapper;
}
+
+ /**
+ * Returns <tt>true</tt> if the type is explicitly specified in the name.
+ */
+ public boolean explicitTypeInName() {
+ return this.explicitTypeInName;
+ }
+
+ /**
+ * The best effort search analyzer associated with this field.
+ */
+ public Analyzer searchAnalyzer() {
+ if (hasMapper()) {
+ Analyzer analyzer = mapper().searchAnalyzer();
+ if (analyzer != null) {
+ return analyzer;
+ }
+ }
+ if (docMapper != null && docMapper.searchAnalyzer() != null) {
+ return docMapper.searchAnalyzer();
+ }
+ return mapperService.searchAnalyzer();
+ }
}
final class SmartIndexNameSearchAnalyzer extends Analyzer {
@@ -79,7 +79,7 @@
throw new QueryParsingException(parseContext.index(), "field_masking_span must have [field] set for it");
}
- FieldMapper mapper = parseContext.mapperService().smartNameFieldMapper(field);
+ FieldMapper mapper = parseContext.fieldMapper(field);
if (mapper != null) {
field = mapper.names().indexName();
}
Oops, something went wrong.

0 comments on commit 6a146e7

Please sign in to comment.