Core: Protects against: 'from + size > scoreDocs.length' in case only single shard response

This commit is contained in:
Martijn van Groningen 2014-05-31 20:28:22 +02:00
parent e8995ecaa7
commit f51a09d8f7
1 changed files with 9 additions and 5 deletions

View File

@ -172,15 +172,19 @@ public class SearchPhaseController extends AbstractComponent {
}
}
if (canOptimize) {
ScoreDoc[] scoreDocs = result.topDocs().scoreDocs;
if (scoreDocs.length == 0) {
return EMPTY_DOCS;
}
int resultDocsSize = scoreDocs.length < result.size() ? scoreDocs.length : result.size();
int offset = result.from();
if (scrollSort) {
offset = 0;
}
ScoreDoc[] scoreDocs = result.topDocs().scoreDocs;
if (scoreDocs.length == 0 || scoreDocs.length < offset) {
return EMPTY_DOCS;
}
int resultDocsSize = result.size();
if ((scoreDocs.length - offset) < resultDocsSize) {
resultDocsSize = scoreDocs.length - offset;
}
ScoreDoc[] docs = new ScoreDoc[resultDocsSize];
for (int i = 0; i < resultDocsSize; i++) {
ScoreDoc scoreDoc = scoreDocs[offset + i];