Skip to content

Apache Lucene open-source search software

LUCENE-6271: fix check index on term vectors use of postings

Ryan Ernst14f3789d1830
diff --git a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
index 2ced105bf9d..e0fb807b487 100644
--- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
+++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
@@ -1821,12 +1821,11 @@ public class CheckIndex implements Closeable {
infoStream.print(" test: term vectors........");
}
- PostingsEnum docs = null;
PostingsEnum postings = null;
// Only used if crossCheckTermVectors is true:
PostingsEnum postingsDocs = null;
- PostingsEnum postingsPostings = null;
+ PostingsEnum postingsDocs2 = null;
final Bits liveDocs = reader.getLiveDocs();
@@ -1898,58 +1897,30 @@ public class CheckIndex implements Closeable {
final boolean hasProx = terms.hasOffsets() || terms.hasPositions();
BytesRef term = null;
while ((term = termsEnum.next()) != null) {
-
- if (hasProx) {
- postings = termsEnum.postings(null, postings, PostingsEnum.ALL);
- assert postings != null;
- docs = null;
- } else {
- docs = termsEnum.postings(null, docs);
- assert docs != null;
- postings = null;
- }
-
- final PostingsEnum docs2;
- if (hasProx) {
- assert postings != null;
- docs2 = postings;
- } else {
- assert docs != null;
- docs2 = docs;
- }
-
- final PostingsEnum postingsDocs2;
+
+ postings = termsEnum.postings(null, postings, PostingsEnum.ALL);
+ assert postings != null;
+
if (!postingsTermsEnum.seekExact(term)) {
throw new RuntimeException("vector term=" + term + " field=" + field + " does not exist in postings; doc=" + j);
}
- postingsPostings = postingsTermsEnum.postings(null, postingsPostings, PostingsEnum.ALL);
- if (postingsPostings == null) {
- // Term vectors were indexed w/ pos but postings were not
- postingsDocs = postingsTermsEnum.postings(null, postingsDocs);
- if (postingsDocs == null) {
- throw new RuntimeException("vector term=" + term + " field=" + field + " does not exist in postings; doc=" + j);
- }
- }
-
- if (postingsPostings != null) {
- postingsDocs2 = postingsPostings;
- } else {
- postingsDocs2 = postingsDocs;
- }
+ postingsDocs2 = postingsTermsEnum.postings(null, postingsDocs2, PostingsEnum.ALL);
+ assert postingsDocs2 != null;
+
final int advanceDoc = postingsDocs2.advance(j);
if (advanceDoc != j) {
throw new RuntimeException("vector term=" + term + " field=" + field + ": doc=" + j + " was not found in postings (got: " + advanceDoc + ")");
}
- final int doc = docs2.nextDoc();
+ final int doc = postings.nextDoc();
if (doc != 0) {
throw new RuntimeException("vector for doc " + j + " didn't return docID=0: got docID=" + doc);
}
if (postingsHasFreq) {
- final int tf = docs2.freq();
+ final int tf = postings.freq();
if (postingsHasFreq && postingsDocs2.freq() != tf) {
throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + ": freq=" + tf + " differs from postings freq=" + postingsDocs2.freq());
}
@@ -1957,8 +1928,8 @@ public class CheckIndex implements Closeable {
if (hasProx) {
for (int i = 0; i < tf; i++) {
int pos = postings.nextPosition();
- if (postingsPostings != null) {
- int postingsPos = postingsPostings.nextPosition();
+ if (postingsTerms.hasPositions()) {
+ int postingsPos = postingsDocs2.nextPosition();
if (terms.hasPositions() && pos != postingsPos) {
throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + ": pos=" + pos + " differs from postings pos=" + postingsPos);
}
@@ -1978,17 +1949,14 @@ public class CheckIndex implements Closeable {
}
lastStartOffset = startOffset;
*/
-
- if (postingsPostings != null) {
- final int postingsStartOffset = postingsPostings.startOffset();
-
- final int postingsEndOffset = postingsPostings.endOffset();
- if (startOffset != -1 && postingsStartOffset != -1 && startOffset != postingsStartOffset) {
- throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + ": startOffset=" + startOffset + " differs from postings startOffset=" + postingsStartOffset);
- }
- if (endOffset != -1 && postingsEndOffset != -1 && endOffset != postingsEndOffset) {
- throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + ": endOffset=" + endOffset + " differs from postings endOffset=" + postingsEndOffset);
- }
+
+ final int postingsStartOffset = postingsDocs2.startOffset();
+ final int postingsEndOffset = postingsDocs2.endOffset();
+ if (startOffset != -1 && postingsStartOffset != -1 && startOffset != postingsStartOffset) {
+ throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + ": startOffset=" + startOffset + " differs from postings startOffset=" + postingsStartOffset);
+ }
+ if (endOffset != -1 && postingsEndOffset != -1 && endOffset != postingsEndOffset) {
+ throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + ": endOffset=" + endOffset + " differs from postings endOffset=" + postingsEndOffset);
}
BytesRef payload = postings.getPayload();
@@ -1998,21 +1966,20 @@ public class CheckIndex implements Closeable {
}
if (postingsHasPayload && vectorsHasPayload) {
- assert postingsPostings != null;
if (payload == null) {
// we have payloads, but not at this position.
// postings has payloads too, it should not have one at this position
- if (postingsPostings.getPayload() != null) {
- throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + " has no payload but postings does: " + postingsPostings.getPayload());
+ if (postingsDocs2.getPayload() != null) {
+ throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + " has no payload but postings does: " + postingsDocs2.getPayload());
}
} else {
// we have payloads, and one at this position
// postings should also have one at this position, with the same bytes.
- if (postingsPostings.getPayload() == null) {
+ if (postingsDocs2.getPayload() == null) {
throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + " has payload=" + payload + " but postings does not.");
}
- BytesRef postingsPayload = postingsPostings.getPayload();
+ BytesRef postingsPayload = postingsDocs2.getPayload();
if (!payload.equals(postingsPayload)) {
throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + " has payload=" + payload + " but differs from postings payload=" + postingsPayload);
}