Index: src/test/org/apache/lucene/index/TestCheckIndex.java =================================================================== --- src/test/org/apache/lucene/index/TestCheckIndex.java (revision 785749) +++ src/test/org/apache/lucene/index/TestCheckIndex.java (working copy) @@ -50,6 +50,7 @@ ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); CheckIndex checker = new CheckIndex(dir); checker.setInfoStream(new PrintStream(bos)); + //checker.setInfoStream(System.out); CheckIndex.Status indexStatus = checker.checkIndex(); if (indexStatus.clean == false) { System.out.println("CheckIndex failed"); @@ -61,6 +62,27 @@ assertTrue(seg.openReaderPassed); assertNotNull(seg.diagnostics); + + assertNotNull(seg.fieldNormStatus); + assertNull(seg.fieldNormStatus.error); + assertEquals(1, seg.fieldNormStatus.totFields); + + assertNotNull(seg.termIndexStatus); + assertNull(seg.termIndexStatus.error); + assertEquals(1, seg.termIndexStatus.termCount); + assertEquals(19, seg.termIndexStatus.totFreq); + assertEquals(18, seg.termIndexStatus.totPos); + + assertNotNull(seg.storedFieldStatus); + assertNull(seg.storedFieldStatus.error); + assertEquals(18, seg.storedFieldStatus.docCount); + assertEquals(18, seg.storedFieldStatus.totFields); + + assertNotNull(seg.termVectorStatus); + assertNull(seg.termVectorStatus.error); + assertEquals(18, seg.termVectorStatus.docCount); + assertEquals(18, seg.termVectorStatus.totVectors); + assertTrue(seg.diagnostics.size() > 0); final List onlySegments = new ArrayList(); onlySegments.add("_0"); Index: src/java/org/apache/lucene/index/CheckIndex.java =================================================================== --- src/java/org/apache/lucene/index/CheckIndex.java (revision 785749) +++ src/java/org/apache/lucene/index/CheckIndex.java (working copy) @@ -179,7 +179,77 @@ * debugging details that IndexWriter records into * each segment it creates */ public Map diagnostics; + + /** Status for testing of field norms (null if field norms could not be tested). */ + public FieldNormStatus fieldNormStatus; + + /** Status for testing of indexed terms (null if indexed terms could not be tested). */ + public TermIndexStatus termIndexStatus; + + /** Status for testing of stored fields (null if stored fields could not be tested). */ + public StoredFieldStatus storedFieldStatus; + + /** Status for testing of term vectors (null if term vectors could not be tested). */ + public TermVectorStatus termVectorStatus; } + + /** + * Status from testing field norms. + */ + public static final class FieldNormStatus { + /** Number of fields successfully tested */ + public long totFields = 0L; + + /** Exception thrown during term index test (null on success) */ + public Throwable error = null; + } + + /** + * Status from testing term index. + */ + public static final class TermIndexStatus { + /** Total term count */ + public long termCount = 0L; + + /** Total frequency across all terms. */ + public long totFreq = 0L; + + /** Total number of positions. */ + public long totPos = 0L; + + /** Exception thrown during term index test (null on success) */ + public Throwable error = null; + } + + /** + * Status from testing stored fields. + */ + public static final class StoredFieldStatus { + + /** Number of documents tested. */ + public int docCount = 0; + + /** Total number of stored fields tested. */ + public long totFields = 0; + + /** Exception thrown during stored fields test (null on success) */ + public Throwable error = null; + } + + /** + * Status from testing stored fields. + */ + public static final class TermVectorStatus { + + /** Number of documents tested. */ + public int docCount = 0; + + /** Total number of term vectors tested. */ + public long totVectors = 0; + + /** Exception thrown during term vector test (null on success) */ + public Throwable error = null; + } } /** Create a new CheckIndex on the directory. */ @@ -443,107 +513,38 @@ if (reader.maxDoc() != info.docCount) throw new RuntimeException("SegmentReader.maxDoc() " + reader.maxDoc() + " != SegmentInfos.docCount " + info.docCount); - if (infoStream != null) - infoStream.print(" test: fields, norms......."); + // Test getFieldNames() + if (infoStream != null) { + infoStream.print(" test: fields.............."); + } Collection fieldNames = reader.getFieldNames(IndexReader.FieldOption.ALL); - Iterator it = fieldNames.iterator(); - final byte[] b = new byte[reader.maxDoc()]; - while(it.hasNext()) { - final String fieldName = (String) it.next(); - reader.norms(fieldName, b, 0); - } msg("OK [" + fieldNames.size() + " fields]"); segInfoStat.numFields = fieldNames.size(); - if (infoStream != null) - infoStream.print(" test: terms, freq, prox..."); - final TermEnum termEnum = reader.terms(); - final TermPositions termPositions = reader.termPositions(); + + // Test Field Norms + segInfoStat.fieldNormStatus = testFieldNorms(fieldNames, reader); - // Used only to count up # deleted docs for this - // term - final MySegmentTermDocs myTermDocs = new MySegmentTermDocs(reader); + // Test the Term Index + segInfoStat.termIndexStatus = testTermIndex(info, reader); - long termCount = 0; - long totFreq = 0; - long totPos = 0; - final int maxDoc = reader.maxDoc(); + // Test Stored Fields + segInfoStat.storedFieldStatus = testStoredFields(info, reader, nf); - while(termEnum.next()) { - termCount++; - final Term term = termEnum.term(); - final int docFreq = termEnum.docFreq(); - termPositions.seek(term); - int lastDoc = -1; - int freq0 = 0; - totFreq += docFreq; - while(termPositions.next()) { - freq0++; - final int doc = termPositions.doc(); - final int freq = termPositions.freq(); - if (doc <= lastDoc) - throw new RuntimeException("term " + term + ": doc " + doc + " <= lastDoc " + lastDoc); - if (doc >= maxDoc) - throw new RuntimeException("term " + term + ": doc " + doc + " >= maxDoc " + maxDoc); + // Test Term Vectors + segInfoStat.termVectorStatus = testTermVectors(info, reader, nf); - lastDoc = doc; - if (freq <= 0) - throw new RuntimeException("term " + term + ": doc " + doc + ": freq " + freq + " is out of bounds"); - - int lastPos = -1; - totPos += freq; - for(int j=0;j= maxDoc) + throw new RuntimeException("term " + term + ": doc " + doc + " >= maxDoc " + maxDoc); + + lastDoc = doc; + if (freq <= 0) + throw new RuntimeException("term " + term + ": doc " + doc + ": freq " + freq + " is out of bounds"); + + int lastPos = -1; + status.totPos += freq; + for(int j=0;j