Skip to content

Commit

Permalink
LUCENE-10674: Ensure BitSetConjDISI returns NO_MORE_DOCS when sub-ite…
Browse files Browse the repository at this point in the history
…rator exhausts. (#1068)

Signed-off-by: John Mazanec <jmazane@amazon.com>
  • Loading branch information
jmazanec15 authored and jpountz committed Sep 15, 2022
1 parent 133598a commit 891a696
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ API Changes

Bug Fixes
---------------------

* GITHUB#11726: Indexing term vectors on large documents could fail due to
trying to apply a dictionary whose size is greater than the maximum supported
window size for LZ4. (Adrien Grand)

* LUCENE-10674: Ensure BitSetConjDISI returns NO_MORE_DOCS when sub-iterator exhausts. (Jack Mazanec)

Other
---------------------
* LUCENE-10423: Remove usages of System.currentTimeMillis() from tests. (Marios Trivyzas)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ private int doNext(int doc) throws IOException {
advanceLead:
for (; ; doc = lead.nextDoc()) {
if (doc >= minLength) {
if (doc != NO_MORE_DOCS) {
lead.advance(NO_MORE_DOCS);
}
return NO_MORE_DOCS;
}
for (BitSet bitSet : bitSets) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.lucene.search;

import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -213,9 +215,7 @@ private static FixedBitSet intersect(FixedBitSet[] bitSets) {

private static FixedBitSet toBitSet(int maxDoc, DocIdSetIterator iterator) throws IOException {
final FixedBitSet set = new FixedBitSet(maxDoc);
for (int doc = iterator.nextDoc();
doc != DocIdSetIterator.NO_MORE_DOCS;
doc = iterator.nextDoc()) {
for (int doc = iterator.nextDoc(); doc != NO_MORE_DOCS; doc = iterator.nextDoc()) {
set.set(doc);
}
return set;
Expand Down Expand Up @@ -459,4 +459,29 @@ public void testIllegalAdvancementOfSubIteratorsTripsAssertion() throws IOExcept
AssertionError ex = expectThrows(AssertionError.class, () -> conjunction.nextDoc());
assertEquals("Sub-iterators of ConjunctionDISI are not on the same document!", ex.getMessage());
}

public void testBitSetConjunctionDISIDocIDOnExhaust() throws IOException {
int numBitSetIterators = TestUtil.nextInt(random(), 2, 5);
DocIdSetIterator[] iterators = new DocIdSetIterator[numBitSetIterators + 1];

// Create sparse DocIdSetIterator with a single match that is greater than lengths of bitset
// iterators
int maxBitSetLength = 1000;
int minBitSetLength = 2;
int leadMaxDoc = maxBitSetLength + 1;
iterators[iterators.length - 1] = DocIdSetIterator.range(leadMaxDoc, leadMaxDoc + 1);

for (int i = 0; i < numBitSetIterators; i++) {
int bitSetLength = TestUtil.nextInt(random(), minBitSetLength, maxBitSetLength);
FixedBitSet bitSet = new FixedBitSet(bitSetLength);
bitSet.set(0, bitSetLength - 1);
iterators[i] = new BitDocIdSet(bitSet).iterator();
}

final DocIdSetIterator conjunction =
ConjunctionUtils.intersectIterators(Arrays.asList(iterators));

assertEquals(NO_MORE_DOCS, conjunction.nextDoc());
assertEquals(NO_MORE_DOCS, conjunction.docID());
}
}

0 comments on commit 891a696

Please sign in to comment.