LUCENE-6271: simplify CheckIndex's PostingsEnum uses

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene6271@1670380 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan Ernst 2015-03-31 16:11:32 +00:00
parent 198ec5516b
commit ca6a9ca92a
1 changed files with 22 additions and 34 deletions

View File

@ -917,8 +917,7 @@ public class CheckIndex implements Closeable {
final Status.TermIndexStatus status = new Status.TermIndexStatus();
int computedFieldCount = 0;
PostingsEnum docs = null;
PostingsEnum postings = null;
String lastField = null;
@ -1068,9 +1067,7 @@ public class CheckIndex implements Closeable {
throw new RuntimeException("docfreq: " + docFreq + " is out of bounds");
}
sumDocFreq += docFreq;
docs = termsEnum.postings(liveDocs, docs);
// nocommit: check null
postings = termsEnum.postings(liveDocs, postings, PostingsEnum.ALL);
if (hasFreqs == false) {
@ -1095,18 +1092,11 @@ public class CheckIndex implements Closeable {
}
}
final PostingsEnum docs2;
if (postings != null) {
docs2 = postings;
} else {
docs2 = docs;
}
int lastDoc = -1;
int docCount = 0;
long totalTermFreq = 0;
while(true) {
final int doc = docs2.nextDoc();
final int doc = postings.nextDoc();
if (doc == DocIdSetIterator.NO_MORE_DOCS) {
break;
}
@ -1114,7 +1104,7 @@ public class CheckIndex implements Closeable {
visitedDocs.set(doc);
int freq = -1;
if (hasFreqs) {
freq = docs2.freq();
freq = postings.freq();
if (freq <= 0) {
throw new RuntimeException("term " + term + ": doc " + doc + ": freq " + freq + " is out of bounds");
}
@ -1124,7 +1114,7 @@ public class CheckIndex implements Closeable {
// When a field didn't index freq, it must
// consistently "lie" and pretend that freq was
// 1:
if (docs2.freq() != 1) {
if (postings.freq() != 1) {
throw new RuntimeException("term " + term + ": doc " + doc + ": freq " + freq + " != 1 when Terms.hasFreqs() is false");
}
}
@ -1196,20 +1186,20 @@ public class CheckIndex implements Closeable {
// Re-count if there are deleted docs:
if (liveDocs != null) {
if (hasFreqs) {
docs = termsEnum.postings(null, docs);
postings = termsEnum.postings(null, postings);
docCount = 0;
totalTermFreq = 0;
while(docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
visitedDocs.set(docs.docID());
while(postings.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
visitedDocs.set(postings.docID());
docCount++;
totalTermFreq += docs.freq();
totalTermFreq += postings.freq();
}
} else {
docs = termsEnum.postings(null, docs, PostingsEnum.NONE);
postings = termsEnum.postings(null, postings, PostingsEnum.NONE);
docCount = 0;
totalTermFreq = -1;
while(docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
visitedDocs.set(docs.docID());
while(postings.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
visitedDocs.set(postings.docID());
docCount++;
}
}
@ -1296,15 +1286,15 @@ public class CheckIndex implements Closeable {
} else {
for(int idx=0;idx<7;idx++) {
final int skipDocID = (int) (((idx+1)*(long) maxDoc)/8);
docs = termsEnum.postings(liveDocs, docs, PostingsEnum.NONE);
final int docID = docs.advance(skipDocID);
postings = termsEnum.postings(liveDocs, postings, PostingsEnum.NONE);
final int docID = postings.advance(skipDocID);
if (docID == DocIdSetIterator.NO_MORE_DOCS) {
break;
} else {
if (docID < skipDocID) {
throw new RuntimeException("term " + term + ": advance(docID=" + skipDocID + ") returned docID=" + docID);
}
final int nextDocID = docs.nextDoc();
final int nextDocID = postings.nextDoc();
if (nextDocID == DocIdSetIterator.NO_MORE_DOCS) {
break;
}
@ -1409,13 +1399,12 @@ public class CheckIndex implements Closeable {
throw new RuntimeException("seek to existing term " + seekTerms[i] + " failed");
}
docs = termsEnum.postings(liveDocs, docs, PostingsEnum.NONE);
// nocommit: null check still needed? how to replace?
if (docs == null) {
postings = termsEnum.postings(liveDocs, postings, PostingsEnum.NONE);
if (postings == null) {
throw new RuntimeException("null DocsEnum from to existing term " + seekTerms[i]);
}
while(docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
while (postings.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
totDocCount++;
}
}
@ -1428,13 +1417,12 @@ public class CheckIndex implements Closeable {
}
totDocFreq += termsEnum.docFreq();
docs = termsEnum.postings(null, docs, PostingsEnum.NONE);
// nocommit: null check still needed? how to replace?
if (docs == null) {
postings = termsEnum.postings(null, postings, PostingsEnum.NONE);
if (postings == null) {
throw new RuntimeException("null DocsEnum from to existing term " + seekTerms[i]);
}
while(docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
while(postings.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
totDocCountNoDeletes++;
}
}