private static PivotFacetResult<?> getPivotFacetResult(PivotField pivotField,QueryResponse response, DocumentFactory factory, Map<String, Facet> facetsQuery, String searchContext) {
final String fieldName = getFieldDescriptorName(searchContext, pivotField.getField());
final FieldDescriptor<?> descriptor = factory.getField(fieldName);
if (descriptor == null) {
log.error("Unable to create a pivot faced result: the field '{}' is not configured as facet.", fieldName);
throw new RuntimeException("Unable to create a pivot faced result: the field '"+ fieldName +"' is not configured as facet.");
}
final List<PivotFacetResult<?>> pivot = new ArrayList<>();
if(pivotField.getPivot()!=null) {
pivotField.getPivot().stream().forEach(pivotF -> pivot.add(getPivotFacetResult(pivotF,response,factory,facetsQuery, searchContext)));
}
HashMap<String, QueryFacetResult<?>> pivotQueryResult = new HashMap<>();
if (pivotField.getFacetQuery() != null) {
pivotQueryResult= getFacetQueryResults(pivotField.getFacetQuery().entrySet(),facetsQuery);
}
HashMap<String, RangeFacetResult<?>> pivotRangeResult = new HashMap<>();
if (pivotField.getFacetRanges() != null) {
pivotRangeResult = getRangeFacetResult(pivotField.getFacetRanges(), response, factory, facetsQuery, searchContext);
}
HashMap<String, StatsFacetResult<?>> pivotStatsResults = new HashMap<>();
if(pivotField.getFieldStatsInfo()!=null) {
pivotStatsResults = getStatsFacetsResults(pivotField.getFieldStatsInfo().entrySet(), facetsQuery);
}
return new PivotFacetResult(pivot, pivotField.getValue(), descriptor, pivotField.getCount(),pivotQueryResult, pivotStatsResults, pivotRangeResult);
}