more checkindex

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1411422 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-11-19 21:19:01 +00:00
parent b357f6f8a6
commit e7dc29859f
2 changed files with 29 additions and 1 deletions

View File

@ -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) { private void checkNumericDocValues(FieldInfo fi, SegmentReader reader, NumericDocValues ndv) {
final long minValue = ndv.minValue(); final long minValue = ndv.minValue();
final long maxValue = ndv.maxValue(); final long maxValue = ndv.maxValue();
@ -1416,7 +1439,7 @@ public class CheckIndex {
case BYTES_VAR_SORTED: case BYTES_VAR_SORTED:
case BYTES_FIXED_DEREF: case BYTES_FIXED_DEREF:
case BYTES_VAR_DEREF: case BYTES_VAR_DEREF:
checkBinaryDocValues(fi, reader, reader.getSortedDocValues(fi.name)); checkSortedDocValues(fi, reader, reader.getSortedDocValues(fi.name));
break; break;
case BYTES_FIXED_STRAIGHT: case BYTES_FIXED_STRAIGHT:
case BYTES_VAR_STRAIGHT: case BYTES_VAR_STRAIGHT:

View File

@ -587,7 +587,12 @@ public class TestDemoDocValue extends LuceneTestCase {
assert ireader.leaves().size() == 1; assert ireader.leaves().size() == 1;
SortedDocValues dv = ireader.leaves().get(0).reader().getSortedDocValues("dv"); SortedDocValues dv = ireader.leaves().get(0).reader().getSortedDocValues("dv");
assertTrue(dv.isFixedLength()); // "hello world 1" length == "hello world 2" length assertTrue(dv.isFixedLength()); // "hello world 1" length == "hello world 2" length
assertEquals(2, dv.getValueCount()); // 2 ords
BytesRef scratch = new BytesRef(); BytesRef 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++) { for(int i=0;i<2;i++) {
StoredDocument doc2 = ireader.leaves().get(0).reader().document(i); StoredDocument doc2 = ireader.leaves().get(0).reader().document(i);
String expected; String expected;