LUCENE-7528: Fix Lucene54's advanceExact impl in the sparse case.

This commit is contained in:
Adrien Grand 2016-10-31 10:36:26 +01:00
parent 325b74e0e3
commit 66c90a9683
2 changed files with 28 additions and 1 deletions

View File

@ -715,7 +715,7 @@ final class Lucene54DocValuesProducer extends DocValuesProducer implements Close
} }
--index; --index;
doc = target; doc = target;
return false; return index >= 0 && docIds.get(index) == target;
} }
@Override @Override

View File

@ -488,6 +488,33 @@ public class TestLucene54DocValuesFormat extends BaseCompressingDocValuesFormatT
} }
} }
// advanceExact
for (int i = 0; i < 2000; ++i) {
sparseValues.reset();
if (random().nextBoolean() && docIds.length > 0) {
sparseValues.advance(docIds[TestUtil.nextInt(random(), 0, docIds.length - 1)]);
}
final int target = TestUtil.nextInt(random(), Math.max(0, sparseValues.docID()), maxDoc - 1);
final boolean exists = sparseValues.advanceExact(target);
final int index = Arrays.binarySearch(docIds, target);
assertEquals(index >= 0, exists);
assertEquals(target, sparseValues.docID());
final boolean exists2 = sparseValues.advanceExact(target);
assertEquals(index >= 0, exists2);
assertEquals(target, sparseValues.docID());
final int nextIndex = index >= 0 ? index + 1 : -1 - index;
if (nextIndex >= docIds.length) {
assertEquals(DocIdSetIterator.NO_MORE_DOCS, sparseValues.nextDoc());
} else {
assertEquals(docIds[nextIndex], sparseValues.nextDoc());
}
}
final SparseNumericDocValuesRandomAccessWrapper raWrapper = new SparseNumericDocValuesRandomAccessWrapper(sparseValues, missingValue); final SparseNumericDocValuesRandomAccessWrapper raWrapper = new SparseNumericDocValuesRandomAccessWrapper(sparseValues, missingValue);
// random-access // random-access