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;
}
Aggregations