Skip to content

Apache Lucene open-source search software

Fix wrong BitSet result in MemoryAccountingBitsetCollector (#15656)

gaobinlong305d278a6270
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 9d739e1366b..034d232bf90 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -251,6 +251,8 @@ Bug Fixes
* GITHUB#15731: Fix tessellator failure when a hole is touching another hole in the middle of a segment. In this case
we might fail to detect it and choose a wrong bridge to eliminate the hole. (Ignacio Vera)
+* GITHUB#15656: Fix wrong BitSet result in MemoryAccountingBitsetCollector (Binlong Gao)
+
Other
---------------------
* GITHUB#15586: Document that scoring and ranking may change across major Lucene versions, and that applications requiring stable ranking should explicitly configure Similarity. (Parveen Saini)
diff --git a/lucene/misc/src/java/org/apache/lucene/misc/search/MemoryAccountingBitsetCollector.java b/lucene/misc/src/java/org/apache/lucene/misc/search/MemoryAccountingBitsetCollector.java
index 21e3c58537a..a2337ab033e 100644
--- a/lucene/misc/src/java/org/apache/lucene/misc/search/MemoryAccountingBitsetCollector.java
+++ b/lucene/misc/src/java/org/apache/lucene/misc/search/MemoryAccountingBitsetCollector.java
@@ -39,6 +39,7 @@ public class MemoryAccountingBitsetCollector extends SimpleCollector {
@Override
protected void doSetNextReader(LeafReaderContext context) throws IOException {
+ docBase = context.docBase;
length += context.reader().maxDoc();
FixedBitSet newBitSet = FixedBitSet.ensureCapacity(bitSet, length);
if (newBitSet != bitSet) {
diff --git a/lucene/misc/src/test/org/apache/lucene/misc/search/TestMemoryAccountingBitsetCollector.java b/lucene/misc/src/test/org/apache/lucene/misc/search/TestMemoryAccountingBitsetCollector.java
index a77fb564942..b642cf8f171 100644
--- a/lucene/misc/src/test/org/apache/lucene/misc/search/TestMemoryAccountingBitsetCollector.java
+++ b/lucene/misc/src/test/org/apache/lucene/misc/search/TestMemoryAccountingBitsetCollector.java
@@ -70,4 +70,18 @@ public class TestMemoryAccountingBitsetCollector extends LuceneTestCase {
searcher.search(MatchAllDocsQuery.INSTANCE, bitSetCollector);
});
}
+
+ public void testCollectedResult() throws Exception {
+ CollectorMemoryTracker tracker =
+ new CollectorMemoryTracker("testMemoryTracker", Long.MAX_VALUE);
+ MemoryAccountingBitsetCollector collector = new MemoryAccountingBitsetCollector(tracker);
+
+ IndexSearcher searcher = new IndexSearcher(reader);
+ searcher.search(MatchAllDocsQuery.INSTANCE, collector);
+
+ assertEquals(1000, collector.bitSet.cardinality());
+ for (int i = 0; i < 1000; i++) {
+ assertTrue(collector.bitSet.get(i));
+ }
+ }
}