LUCENE-8464: Fix legacy.TestMultiValuedNumericRangeQuery to count the number of hits accurately

This commit is contained in:
Jim Ferenczi 2018-11-19 09:42:48 +01:00
parent a0788a7b5e
commit 759af0127c
1 changed files with 7 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
@ -71,8 +72,12 @@ public class TestMultiValuedNumericRangeQuery extends LuceneTestCase {
}
TermRangeQuery cq=TermRangeQuery.newStringRange("asc", format.format(lower), format.format(upper), true, true);
LegacyNumericRangeQuery<Integer> tq= LegacyNumericRangeQuery.newIntRange("trie", lower, upper, true, true);
TopDocs trTopDocs = searcher.search(cq, 1);
TopDocs nrTopDocs = searcher.search(tq, 1);
TopScoreDocCollector trCollector = TopScoreDocCollector.create(1, Integer.MAX_VALUE);
TopScoreDocCollector nrCollector = TopScoreDocCollector.create(1, Integer.MAX_VALUE);
searcher.search(cq, trCollector);
searcher.search(tq, nrCollector);
TopDocs trTopDocs = trCollector.topDocs();
TopDocs nrTopDocs = nrCollector.topDocs();
assertEquals("Returned count for LegacyNumericRangeQuery and TermRangeQuery must be equal", trTopDocs.totalHits.value, nrTopDocs.totalHits.value );
}
reader.close();