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 6a146e7 commit 673655cc7b7ab115257f75e64be4c9d918fc9144 @kimchy kimchy committed Oct 17, 2011
View
30 modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MapperService.java
@@ -446,6 +446,36 @@ public ObjectMappers objectMapper(String path) {
return fields;
}
+ public SmartNameObjectMapper smartNameObjectMapper(String smartName, @Nullable String[] types) {
+ if (types == null || types.length == 0) {
+ return smartNameObjectMapper(smartName);
+ }
+ for (String type : types) {
+ DocumentMapper possibleDocMapper = mappers.get(type);
+ if (possibleDocMapper != null) {
+ ObjectMapper mapper = possibleDocMapper.objectMappers().get(smartName);
+ if (mapper != null) {
+ return new SmartNameObjectMapper(mapper, possibleDocMapper);
+ }
+ }
+ }
+ // did not find one, see if its prefixed by type
+ int dotIndex = smartName.indexOf('.');
+ if (dotIndex != -1) {
+ String possibleType = smartName.substring(0, dotIndex);
+ DocumentMapper possibleDocMapper = mappers.get(possibleType);
+ if (possibleDocMapper != null) {
+ String possiblePath = smartName.substring(dotIndex + 1);
+ ObjectMapper mapper = possibleDocMapper.objectMappers().get(possiblePath);
+ if (mapper != null) {
+ return new SmartNameObjectMapper(mapper, possibleDocMapper);
+ }
+ }
+ }
+ // did not explicitly find one under the types provided, or prefixed by type...
+ return null;
+ }
+
public SmartNameObjectMapper smartNameObjectMapper(String smartName) {
int dotIndex = smartName.indexOf('.');
if (dotIndex != -1) {
View
2 modules/elasticsearch/src/main/java/org/elasticsearch/index/query/NestedFilterParser.java
@@ -105,7 +105,7 @@
query.setBoost(boost);
- MapperService.SmartNameObjectMapper mapper = parseContext.mapperService().smartNameObjectMapper(path);
+ MapperService.SmartNameObjectMapper mapper = parseContext.smartObjectMapper(path);
if (mapper == null) {
throw new QueryParsingException(parseContext.index(), "[nested] failed to find nested object under path [" + path + "]");
}
View
2 modules/elasticsearch/src/main/java/org/elasticsearch/index/query/NestedQueryParser.java
@@ -110,7 +110,7 @@
query.setBoost(boost);
- MapperService.SmartNameObjectMapper mapper = parseContext.mapperService().smartNameObjectMapper(path);
+ MapperService.SmartNameObjectMapper mapper = parseContext.smartObjectMapper(path);
if (mapper == null) {
throw new QueryParsingException(parseContext.index(), "[nested] failed to find nested object under path [" + path + "]");
}
View
5 modules/elasticsearch/src/main/java/org/elasticsearch/index/query/QueryParseContext.java
@@ -223,4 +223,9 @@ public String indexName(String name) {
SearchContext searchContext = SearchContext.current();
return indexQueryParser.mapperService.smartName(name, searchContext == null ? null : searchContext.types());
}
+
+ public MapperService.SmartNameObjectMapper smartObjectMapper(String name) {
+ SearchContext searchContext = SearchContext.current();
+ return indexQueryParser.mapperService.smartNameObjectMapper(name, searchContext == null ? null : searchContext.types());
+ }
}
View
2 modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/FacetParseElement.java
@@ -113,7 +113,7 @@
if (nestedPath != null) {
// its a nested facet, wrap the collector with a facet one...
- MapperService.SmartNameObjectMapper mapper = context.mapperService().smartNameObjectMapper(nestedPath);
+ MapperService.SmartNameObjectMapper mapper = context.smartNameObjectMapper(nestedPath);
if (mapper == null) {
throw new SearchParseException(context, "facet nested path [" + nestedPath + "] not found");
}
View
4 modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java
@@ -546,4 +546,8 @@ public FieldMappers smartNameFieldMappers(String name) {
public FieldMapper smartNameFieldMapper(String name) {
return mapperService().smartNameFieldMapper(name, types);
}
+
+ public MapperService.SmartNameObjectMapper smartNameObjectMapper(String name) {
+ return mapperService().smartNameObjectMapper(name, types);
+ }
}

0 comments on commit 673655c

Please sign in to comment.