Search in sources :

Example 1 with GroupOrder

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;
}
Also used : Group(org.apache.metron.indexing.dao.search.Group) GroupResult(org.apache.metron.indexing.dao.search.GroupResult) ArrayList(java.util.ArrayList) PivotField(org.apache.solr.client.solrj.response.PivotField) GroupOrder(org.apache.metron.indexing.dao.search.GroupOrder)

Aggregations

ArrayList (java.util.ArrayList)1 Group (org.apache.metron.indexing.dao.search.Group)1 GroupOrder (org.apache.metron.indexing.dao.search.GroupOrder)1 GroupResult (org.apache.metron.indexing.dao.search.GroupResult)1 PivotField (org.apache.solr.client.solrj.response.PivotField)1