use of org.apache.metron.indexing.dao.search.GroupOrder in project metron by apache.
the class SolrSearchDao method getGroupResults.
protected List<GroupResult> getGroupResults(GroupRequest groupRequest, int index, List<PivotField> pivotFields) {
List<Group> groups = groupRequest.getGroups();
List<GroupResult> searchResultGroups = new ArrayList<>();
final GroupOrder groupOrder = groups.get(index).getOrder();
pivotFields.sort((o1, o2) -> {
String s1 = groupOrder.getGroupOrderType() == GroupOrderType.TERM ? o1.getValue().toString() : Integer.toString(o1.getCount());
String s2 = groupOrder.getGroupOrderType() == GroupOrderType.TERM ? o2.getValue().toString() : Integer.toString(o2.getCount());
if (groupOrder.getSortOrder() == SortOrder.ASC) {
return s1.compareTo(s2);
} else {
return s2.compareTo(s1);
}
});
for (PivotField pivotField : pivotFields) {
GroupResult groupResult = new GroupResult();
groupResult.setKey(pivotField.getValue().toString());
groupResult.setTotal(pivotField.getCount());
Optional<String> scoreField = groupRequest.getScoreField();
if (scoreField.isPresent()) {
groupResult.setScore((Double) pivotField.getFieldStatsInfo().get(scoreField.get()).getSum());
}
if (index < groups.size() - 1) {
groupResult.setGroupedBy(groups.get(index + 1).getField());
groupResult.setGroupResults(getGroupResults(groupRequest, index + 1, pivotField.getPivot()));
}
searchResultGroups.add(groupResult);
}
return searchResultGroups;
}
Aggregations