LUCENE-8627: Fix SearchAfter#testQueries to always count the number of hits accurately.

This commit is contained in:
Jim Ferenczi 2019-01-02 09:37:10 +01:00
parent 5016959ce8
commit 7c70365811
1 changed files with 24 additions and 7 deletions

View File

@ -216,14 +216,24 @@ public class TestSearchAfter extends LuceneTestCase {
if (VERBOSE) {
System.out.println("\nassertQuery " + (iter++) + ": query=" + query + " sort=" + sort + " pageSize=" + pageSize);
}
final boolean doScores = random().nextBoolean();
final boolean doScores;
final TopDocsCollector allCollector;
if (sort == null) {
all = searcher.search(query, maxDoc);
allCollector = TopScoreDocCollector.create(maxDoc, null, Integer.MAX_VALUE);
doScores = false;
} else if (sort == Sort.RELEVANCE) {
all = searcher.search(query, maxDoc, sort, true);
allCollector = TopFieldCollector.create(sort, maxDoc, Integer.MAX_VALUE);
doScores = true;
} else {
all = searcher.search(query, maxDoc, sort, doScores);
allCollector = TopFieldCollector.create(sort, maxDoc, Integer.MAX_VALUE);
doScores = random().nextBoolean();
}
searcher.search(query, allCollector);
all = allCollector.topDocs();
if (doScores) {
TopFieldCollector.populateScores(all.scoreDocs, searcher, query);
}
if (VERBOSE) {
System.out.println(" all.totalHits.value=" + all.totalHits.value);
int upto = 0;
@ -235,21 +245,28 @@ public class TestSearchAfter extends LuceneTestCase {
ScoreDoc lastBottom = null;
while (pageStart < all.totalHits.value) {
TopDocs paged;
final TopDocsCollector pagedCollector;
if (sort == null) {
if (VERBOSE) {
System.out.println(" iter lastBottom=" + lastBottom);
}
paged = searcher.searchAfter(lastBottom, query, pageSize);
pagedCollector = TopScoreDocCollector.create(pageSize, lastBottom, Integer.MAX_VALUE);
} else {
if (VERBOSE) {
System.out.println(" iter lastBottom=" + lastBottom);
}
if (sort == Sort.RELEVANCE) {
paged = searcher.searchAfter(lastBottom, query, pageSize, sort, true);
pagedCollector = TopFieldCollector.create(sort, pageSize, (FieldDoc) lastBottom, Integer.MAX_VALUE);
} else {
paged = searcher.searchAfter(lastBottom, query, pageSize, sort, doScores);
pagedCollector = TopFieldCollector.create(sort, pageSize, (FieldDoc) lastBottom, Integer.MAX_VALUE);
}
}
searcher.search(query, pagedCollector);
paged = pagedCollector.topDocs();
if (doScores) {
TopFieldCollector.populateScores(paged.scoreDocs, searcher, query);
}
if (VERBOSE) {
System.out.println(" " + paged.scoreDocs.length + " hits on page");
}