synchronized(execution) {
for (Results<GroupedSearchResults> result : execution.getResultsList()) {
@SuppressWarnings("unchecked")
int numSearcher = ((CallableWithId<GroupedSearchResults, Integer>)result.getTask()).getId();
if (result.isFinishedOk()) {
GroupedSearchResults gsr = result.getResults();
goodResultsMap.put(numSearcher, gsr);
totalDocuments += gsr.totalGroupsEstimation();
// gather stats from the uni-searchers
Statistics.getStatistics().notifyEventValue("averageTimes_" + searchers.get(numSearcher).getTextualIdentifier(), gsr.getResponseTime());
} else {
badResults++;
logger.warn("Exception from remote searcher " + numSearcher, result.getException());
//gather stats of searcher failures
Statistics.getStatistics().notifyEventError("averageTimes_" + searchers.get(numSearcher).getTextualIdentifier());
badResultsMap.put(numSearcher, result.getException().getMessage());
}
}
}
//move (sorted) entries to a list
for (Map.Entry<Integer, GroupedSearchResults> entry : goodResultsMap.entrySet()) {
goodResults.add(entry.getValue());
}
int resultsSize = goodResults.size();
logger.debug("obtained " + totalDocuments + " documents in "+ resultsSize + " good responses and " + badResults + " exceptions in " + (System.currentTimeMillis() - start) + " ms ");
GroupedSearchResults gsr= null;
if (goodResults.size() == 0) {
logger.warn("No good results - " + badResults + " exceptions");
gsr = new GroupedSearchResults();
} else {
//done collecting results, either because we have results from all the searchers or because we timed out
//now we generate a result vector with the top results of each set
AResultsGrouper grouper = group.getGrouper(new GroupedSearchResultsDocumentProvider(goodResults,sort));
gsr = grouper.group(count,groupSize,firstResult);
}
MultiGSR result = new MultiGSR(gsr,searchers.size());
for (Entry<Integer, GroupedSearchResults> entry: goodResultsMap.entrySet()){
int searcherNum= entry.getKey();
GroupedSearchResults tgsr = entry.getValue();
result.setData(searcherNum, tgsr.getResponseTime(), tgsr.groups());
}
for (Entry<Integer, String> entry: badResultsMap.entrySet()){
int searcherNum= entry.getKey();
result.setData(searcherNum, -1L, -1);
logger.warn("Searcher " + entry.getKey() + " failed with " + entry.getValue());