Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUCENE-10674: Ensure BitSetConjDISI returns NO_MORE_DOCS when sub-iterator exhausts #1068

Merged
merged 5 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ Other

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());
}
}