LUCENE-10598: SortedSetDocValues#docValueCount() should be always greater than zero (#934)

* LUCENE-10598: SortedSetDocValues#docValueCount() should be always greater than zero
This commit is contained in:
Lu Xugang 2022-06-02 01:33:47 +08:00 committed by GitHub
parent 4c53a53238
commit a383253fe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 3 deletions

View File

@ -90,6 +90,8 @@ Bug Fixes
* LUCENE-10582: Fix merging of overridden CollectionStatistics in CombinedFieldQuery (Yannick Welsch)
* LUCENE-10598: SortedSetDocValues#docValueCount() should be always greater than zero. (Lu Xugang)
Other
---------------------

View File

@ -1454,7 +1454,7 @@ final class Lucene90DocValuesProducer extends DocValuesProducer {
@Override
public long docValueCount() {
return count;
return ords.docValueCount();
}
@Override

View File

@ -3337,9 +3337,22 @@ public final class CheckIndex implements Closeable {
LongBitSet seenOrds = new LongBitSet(dv.getValueCount());
long maxOrd2 = -1;
for (int docID = dv.nextDoc(); docID != NO_MORE_DOCS; docID = dv.nextDoc()) {
long count = dv.docValueCount();
if (count == 0) {
throw new CheckIndexException(
"sortedset dv for field: "
+ fieldName
+ " returned docValueCount=0 for docID="
+ docID);
}
if (dv2.advanceExact(docID) == false) {
throw new CheckIndexException("advanceExact did not find matching doc ID: " + docID);
}
long count2 = dv2.docValueCount();
if (count != count2) {
throw new CheckIndexException(
"advanceExact reports different value count: " + count + " != " + count2);
}
long lastOrd = -1;
long ord;
int ordCount = 0;

View File

@ -45,8 +45,9 @@ public abstract class SortedSetDocValues extends DocValuesIterator {
public abstract long nextOrd() throws IOException;
/**
* Retrieves the number of values for the current document. This must always be greater than zero.
* It is illegal to call this method after {@link #advanceExact(int)} returned {@code false}.
* Retrieves the number of unique ords for the current document. This must always be greater than
* zero. It is illegal to call this method after {@link #advanceExact(int)} returned {@code
* false}.
*/
public abstract long docValueCount();

View File

@ -265,6 +265,7 @@ public class TestLucene90DocValuesFormat extends BaseCompressingDocValuesFormatT
assertTrue(valueSet.contains(sortedNumeric.nextValue()));
}
assertEquals(i, sortedSet.nextDoc());
assertEquals(valueSet.size(), sortedSet.docValueCount());
int sortedSetCount = 0;
while (true) {
long ord = sortedSet.nextOrd();
@ -488,6 +489,7 @@ public class TestLucene90DocValuesFormat extends BaseCompressingDocValuesFormatT
for (int i = 0; i < maxDoc; ++i) {
assertEquals(i, values.nextDoc());
final int numValues = in.readVInt();
assertEquals(numValues, values.docValueCount());
for (int j = 0; j < numValues; ++j) {
b.setLength(in.readVInt());

View File

@ -279,6 +279,7 @@ public class TestMultiDocValues extends LuceneTestCase {
if (docID == NO_MORE_DOCS) {
break;
}
assertEquals(single.docValueCount(), multi.docValueCount());
ArrayList<Long> expectedList = new ArrayList<>();
long ord;

View File

@ -230,6 +230,7 @@ public class TestSortingCodecReader extends LuceneTestCase {
assertEquals(
new BytesRef(ids.longValue() + ""),
sorted_set_dv.lookupOrd(sorted_set_dv.nextOrd()));
assertEquals(1, sorted_set_dv.docValueCount());
assertEquals(1, sorted_numeric_dv.docValueCount());
assertEquals(ids.longValue(), sorted_numeric_dv.nextValue());

View File

@ -297,6 +297,7 @@ public class TestMemoryIndex extends LuceneTestCase {
SortedSetDocValues sortedSetDocValues = leafReader.getSortedSetDocValues("sorted_set");
assertEquals(3, sortedSetDocValues.getValueCount());
assertEquals(0, sortedSetDocValues.nextDoc());
assertEquals(3, sortedSetDocValues.docValueCount());
assertEquals(0L, sortedSetDocValues.nextOrd());
assertEquals(1L, sortedSetDocValues.nextOrd());
assertEquals(2L, sortedSetDocValues.nextOrd());