SearchCall call = new SearchCall(shards[i], weight, max, sort, timeout, i);
csSearch.submit(call);
}
final ScoreDoc[][] scoreDocs = new ScoreDoc[shardsCount][];
ScoreDoc scoreDocExample = null;
for (int i = 0; i < shardsCount; i++) {
try {
final SearchResult searchResult = csSearch.take().get();
final int callIndex = searchResult.getSearchCallIndex();
totalHits += searchResult._totalHits;
scoreDocs[callIndex] = searchResult._scoreDocs;
if (scoreDocExample == null && scoreDocs[callIndex].length > 0) {
scoreDocExample = scoreDocs[callIndex][0];
}
} catch (InterruptedException e) {
throw new IOException("Multithread shard search interrupted:", e);
} catch (ExecutionException e) {
throw new IOException("Multithread shard search could not be executed:", e);
}
}
result.addTotalHits(totalHits);
final Iterable<Hit> finalHitList;
// Limit the request to the number requested or the total number of
// documents, whichever is smaller.
int limit = Math.min(numDocs, max);
if (sort == null || totalHits == 0) {
final KattaHitQueue hq = new KattaHitQueue(limit);
int pos = 0;
BitSet done = new BitSet(shardsCount);
while (done.cardinality() != shardsCount) {
ScoreDoc scoreDoc = null;
for (int i = 0; i < shardsCount; i++) {
// only process this shard if it is not yet done.
if (!done.get(i)) {
final ScoreDoc[] docs = scoreDocs[i];
if (pos < docs.length) {