if ("facet_filter".equals(facetFieldName) || "facetFilter".equals(facetFieldName)) {
filter = context.queryParserService().parseInnerFilter(parser);
} else {
FacetProcessor facetProcessor = facetProcessors.processor(facetFieldName);
if (facetProcessor == null) {
throw new SearchParseException(context, "No facet type found for [" + facetFieldName + "]");
}
facet = facetProcessor.parse(topLevelFieldName, parser, context);
}
} else if (token.isValue()) {
if ("global".equals(facetFieldName)) {
if (parser.booleanValue()) {
scope = ContextIndexSearcher.Scopes.GLOBAL;
}
} else if ("scope".equals(facetFieldName) || "_scope".equals(facetFieldName)) {
scope = parser.text();
} else if ("cache_filter".equals(facetFieldName) || "cacheFilter".equals(facetFieldName)) {
cacheFilter = parser.booleanValue();
} else if ("nested".equals(facetFieldName)) {
nestedPath = parser.text();
}
}
}
if (filter != null) {
if (cacheFilter) {
filter = context.filterCache().cache(filter);
}
facet.setFilter(filter);
}
if (nestedPath != null) {
// its a nested facet, wrap the collector with a facet one...
MapperService.SmartNameObjectMapper mapper = context.mapperService().smartNameObjectMapper(nestedPath);
if (mapper == null) {
throw new SearchParseException(context, "facet nested path [" + nestedPath + "] not found");
}
ObjectMapper objectMapper = mapper.mapper();
if (objectMapper == null) {
throw new SearchParseException(context, "facet nested path [" + nestedPath + "] not found");
}
if (!objectMapper.nested().isNested()) {
throw new SearchParseException(context, "facet nested path [" + nestedPath + "] is not nested");
}
facet = new NestedChildrenCollector(facet, context.filterCache().cache(NonNestedDocsFilter.INSTANCE), context.filterCache().cache(objectMapper.nestedTypeFilter()));
}
if (facet == null) {
throw new SearchParseException(context, "no facet type found for facet named [" + topLevelFieldName + "]");
}
if (facetCollectors == null) {
facetCollectors = Lists.newArrayList();
}