Float score = (Float) document.get("score");
if (score == null) {
score = Float.NaN;
}
Object[] sortValues = ((List) document.get("sortValues")).toArray();
scoreDocs[j++] = new ShardDoc(score, sortValues, uniqueId, shard);
}
result.put(key, new QueryCommandResult(new TopDocs(totalHits, scoreDocs, maxScore, sum, max, min), matches));
continue;
}
Integer totalHitCount = (Integer) commandResult.get("totalHitCount");
Integer totalGroupCount = (Integer) commandResult.get("totalGroupCount");
List<GroupDocs<String>> groupDocs = new ArrayList<GroupDocs<String>>();
for (int i = totalGroupCount == null ? 2 : 3; i < commandResult.size(); i++) {
String groupValue = commandResult.getName(i);
@SuppressWarnings("unchecked")
NamedList<Object> groupResult = (NamedList<Object>) commandResult.getVal(i);
Integer totalGroupHits = (Integer) groupResult.get("totalHits");
Float maxScore = (Float) groupResult.get("maxScore");
if (maxScore == null) {
maxScore = Float.NaN;
}
Double sum = (Double) groupResult.get("sum");
Double max = (Double) groupResult.get("max");
Double min = (Double) groupResult.get("min");
if (sum == null) { sum = Double.valueOf(0.0f); }
if (max == null) { max = Double.NEGATIVE_INFINITY; }
if (min == null) { min = Double.POSITIVE_INFINITY; }
@SuppressWarnings("unchecked")
List<NamedList<Object>> documents = (List<NamedList<Object>>) groupResult.get("documents");
ScoreDoc[] scoreDocs = new ScoreDoc[documents.size()];
int j = 0;
for (NamedList<Object> document : documents) {
Object uniqueId = document.get("id").toString();
Float score = (Float) document.get("score");
if (score == null) {
score = Float.NaN;
}
//System.out.println("######### transformToNative:"+document.get("sortValues"));
List sortValuesList = (List) document.get("sortValues");
Object[] sortValues = sortValuesList==null?new Object[0]:sortValuesList.toArray();
scoreDocs[j++] = new ShardDoc(score, sortValues, uniqueId, shard);
}
String groupValueRef = groupValue != null ? groupValue : null;
groupDocs.add(new GroupDocs<String>(maxScore, totalGroupHits, scoreDocs, groupValueRef, null, sum, max, min));
}