Search in sources :

Example 1 with QueryInfo

use of com.xiaomi.linden.thrift.common.QueryInfo in project linden by XiaoMi.

the class LindenResultParser method parse.

public LindenResult parse(TopDocs topDocs, TopGroups<TopDocs> topGroupedDocs, Facets facets, FacetsCollector facetsCollector) throws IOException {
    LindenResult result = new LindenResult();
    List<LindenHit> lindenHits;
    int totalHits = 0;
    if (topDocs != null) {
        totalHits = topDocs.totalHits;
        lindenHits = parseLindenHits(topDocs.scoreDocs);
    } else if (topGroupedDocs != null) {
        lindenHits = new ArrayList<>();
        totalHits = topGroupedDocs.totalHitCount;
        for (GroupDocs<TopDocs> group : topGroupedDocs.groups) {
            List<LindenHit> groupHits = parseLindenHits(group.scoreDocs);
            LindenHit hitGroup = new LindenHit(groupHits.get(0)).setGroupHits(groupHits);
            String groupField = request.getGroupParam().getGroupField();
            String groupValue = LindenUtil.getFieldStringValue(leaves, group.scoreDocs[0].doc, groupField);
            if (!hitGroup.isSetFields()) {
                hitGroup.setFields(new HashMap<String, String>());
            }
            hitGroup.getFields().put(groupField, groupValue);
            lindenHits.add(hitGroup);
        }
        int groupTotal = topGroupedDocs.totalGroupCount == null ? 0 : topGroupedDocs.totalGroupCount;
        result.setTotalGroups(groupTotal);
        result.setTotalGroupHits(topGroupedDocs.totalGroupedHitCount);
    } else {
        lindenHits = new ArrayList<>();
    }
    result.setTotalHits(totalHits);
    result.setHits(lindenHits);
    parseFacets(result, facets, facetsCollector);
    result.setQueryInfo(new QueryInfo().setQuery(query.toString()));
    if (filter != null) {
        result.getQueryInfo().setFilter(filter.toString());
    }
    if (sort != null) {
        result.getQueryInfo().setSort(sort.toString());
    }
    return result;
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) HashMap(java.util.HashMap) LindenHit(com.xiaomi.linden.thrift.common.LindenHit) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GroupDocs(org.apache.lucene.search.grouping.GroupDocs) QueryInfo(com.xiaomi.linden.thrift.common.QueryInfo)

Aggregations

LindenHit (com.xiaomi.linden.thrift.common.LindenHit)1 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)1 QueryInfo (com.xiaomi.linden.thrift.common.QueryInfo)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 GroupDocs (org.apache.lucene.search.grouping.GroupDocs)1