|
47 | 47 | import org.apache.lucene.search.BooleanClause.Occur; |
48 | 48 | import org.apache.lucene.store.Directory; |
49 | 49 | import org.apache.lucene.tests.index.RandomIndexWriter; |
| 50 | +import org.apache.lucene.tests.search.FixedBitSetCollector; |
50 | 51 | import org.apache.lucene.tests.search.QueryUtils; |
51 | 52 | import org.apache.lucene.tests.util.LuceneTestCase; |
52 | 53 | import org.apache.lucene.tests.util.RamUsageTester; |
53 | 54 | import org.apache.lucene.tests.util.TestUtil; |
54 | 55 | import org.apache.lucene.util.BytesRef; |
55 | 56 | import org.apache.lucene.util.BytesRefIterator; |
| 57 | +import org.apache.lucene.util.FixedBitSet; |
56 | 58 | import org.apache.lucene.util.IOUtils; |
57 | 59 | import org.apache.lucene.util.automaton.ByteRunnable; |
58 | 60 |
|
@@ -139,6 +141,9 @@ public void testDuel() throws IOException { |
139 | 141 | iw.commit(); |
140 | 142 | final IndexReader reader = iw.getReader(); |
141 | 143 | final IndexSearcher searcher = newSearcher(reader); |
| 144 | + // This test checks query equivalence, not query-cache behavior. Keep the randomized |
| 145 | + // test-framework searcher, but avoid retaining cached doc-id sets across iterations. |
| 146 | + searcher.setQueryCache(null); |
142 | 147 | iw.close(); |
143 | 148 |
|
144 | 149 | if (reader.numDocs() == 0) { |
@@ -284,17 +289,30 @@ public void testSkipperOptimizationGapAssumption() throws IOException { |
284 | 289 | private void assertSameMatches(IndexSearcher searcher, Query q1, Query q2, boolean scores) |
285 | 290 | throws IOException { |
286 | 291 | final int maxDoc = searcher.getIndexReader().maxDoc(); |
287 | | - final TopDocs td1 = searcher.search(q1, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); |
288 | | - final TopDocs td2 = searcher.search(q2, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); |
289 | | - assertEquals(td1.totalHits.value(), td2.totalHits.value()); |
290 | | - for (int i = 0; i < td1.scoreDocs.length; ++i) { |
291 | | - assertEquals(td1.scoreDocs[i].doc, td2.scoreDocs[i].doc); |
292 | | - if (scores) { |
| 292 | + if (scores) { |
| 293 | + final TopDocs td1 = searcher.search(q1, maxDoc); |
| 294 | + final TopDocs td2 = searcher.search(q2, maxDoc); |
| 295 | + |
| 296 | + assertEquals(td1.totalHits.value(), td2.totalHits.value()); |
| 297 | + for (int i = 0; i < td1.scoreDocs.length; ++i) { |
| 298 | + assertEquals(td1.scoreDocs[i].doc, td2.scoreDocs[i].doc); |
293 | 299 | assertEquals(td1.scoreDocs[i].score, td2.scoreDocs[i].score, 10e-7); |
294 | 300 | } |
| 301 | + } else { |
| 302 | + // For no-score comparisons, only doc-id set equality matters. Avoid materializing |
| 303 | + // all hits as sorted TopDocs for every query pair. |
| 304 | + final FixedBitSet matches1 = collectMatches(searcher, q1, maxDoc); |
| 305 | + final FixedBitSet matches2 = collectMatches(searcher, q2, maxDoc); |
| 306 | + |
| 307 | + assertEquals(matches1, matches2); |
295 | 308 | } |
296 | 309 | } |
297 | 310 |
|
| 311 | + private static FixedBitSet collectMatches(IndexSearcher searcher, Query query, int maxDoc) |
| 312 | + throws IOException { |
| 313 | + return searcher.search(query, FixedBitSetCollector.createManager(maxDoc)); |
| 314 | + } |
| 315 | + |
298 | 316 | public void testHashCodeAndEquals() { |
299 | 317 | int num = atLeast(100); |
300 | 318 | List<BytesRef> terms = new ArrayList<>(); |
|
0 commit comments