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-10582: Fix merging of overridden CollectionStatistics in CombinedFieldQuery (Yannick Welsch)
* LUCENE-10598: SortedSetDocValues#docValueCount() should be always greater than zero. (Lu Xugang)
Other Other
--------------------- ---------------------

View File

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

View File

@ -3337,9 +3337,22 @@ public final class CheckIndex implements Closeable {
LongBitSet seenOrds = new LongBitSet(dv.getValueCount()); LongBitSet seenOrds = new LongBitSet(dv.getValueCount());
long maxOrd2 = -1; long maxOrd2 = -1;
for (int docID = dv.nextDoc(); docID != NO_MORE_DOCS; docID = dv.nextDoc()) { 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) { if (dv2.advanceExact(docID) == false) {
throw new CheckIndexException("advanceExact did not find matching doc ID: " + docID); 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 lastOrd = -1;
long ord; long ord;
int ordCount = 0; int ordCount = 0;

View File

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

View File

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

View File

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

View File

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

View File

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