Apache Lucene open-source search software
more checkindex
Robert Muire7dc29859f99
diff --git a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.javaindex 5123b23b2b9..9ea399405b7 100644--- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java+++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java@@ -1391,6 +1391,29 @@ public class CheckIndex {}}+ private void checkSortedDocValues(FieldInfo fi, SegmentReader reader, SortedDocValues dv) {+ checkBinaryDocValues(fi, reader, dv);+ final int maxOrd = dv.getValueCount()-1;+ int maxOrd2 = -1;+ for (int i = 0; i < reader.maxDoc(); i++) {+ maxOrd2 = Math.max(maxOrd2, dv.getOrd(i));+ }+ if (maxOrd != maxOrd2) {+ throw new RuntimeException("dv for field: " + fi.name + " reports wrong maxOrd=" + maxOrd + " but this is not the case: " + maxOrd2);+ }+ BytesRef lastValue = null;+ BytesRef scratch = new BytesRef();+ for (int i = 0; i <= maxOrd; i++) {+ dv.lookupOrd(i, scratch);+ if (lastValue != null) {+ if (scratch.compareTo(lastValue) <= 0) {+ throw new RuntimeException("dv for field: " + fi.name + " has ords out of order: " + lastValue + " >=" + scratch);+ }+ }+ lastValue = BytesRef.deepCopyOf(scratch);+ }+ }+private void checkNumericDocValues(FieldInfo fi, SegmentReader reader, NumericDocValues ndv) {final long minValue = ndv.minValue();final long maxValue = ndv.maxValue();@@ -1416,7 +1439,7 @@ public class CheckIndex {case BYTES_VAR_SORTED:case BYTES_FIXED_DEREF:case BYTES_VAR_DEREF:- checkBinaryDocValues(fi, reader, reader.getSortedDocValues(fi.name));+ checkSortedDocValues(fi, reader, reader.getSortedDocValues(fi.name));break;case BYTES_FIXED_STRAIGHT:case BYTES_VAR_STRAIGHT:diff --git a/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java b/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.javaindex 11ef5e68f49..d8e88396859 100644--- a/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java+++ b/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java@@ -587,7 +587,12 @@ public class TestDemoDocValue extends LuceneTestCase {assert ireader.leaves().size() == 1;SortedDocValues dv = ireader.leaves().get(0).reader().getSortedDocValues("dv");assertTrue(dv.isFixedLength()); // "hello world 1" length == "hello world 2" length+ assertEquals(2, dv.getValueCount()); // 2 ordsBytesRef scratch = new BytesRef();+ dv.lookupOrd(0, scratch);+ assertEquals(new BytesRef("hello world 1"), scratch);+ dv.lookupOrd(1, scratch);+ assertEquals(new BytesRef("hello world 2"), scratch);for(int i=0;i<2;i++) {StoredDocument doc2 = ireader.leaves().get(0).reader().document(i);String expected;