From 11a6e0de703120d577e9a5efa47168ad80c0a092 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Thu, 7 Apr 2011 21:26:32 +0000 Subject: [PATCH] sharpen CheckIndex to test .nextPosition() after skipping; fix bug in PulsingCodec's reuse of Docs/AndPositionsEnum with payloads; don't write redundant payload lengths git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1090024 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/CheckIndex.java | 69 +++++++++++++++---- .../pulsing/PulsingPostingsReaderImpl.java | 23 ++++--- .../pulsing/PulsingPostingsWriterImpl.java | 2 +- .../lucene/store/MockDirectoryWrapper.java | 3 + .../apache/lucene/index/TestIndexWriter.java | 1 + 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/src/java/org/apache/lucene/index/CheckIndex.java index f3478629fdb..61b3fc07da0 100644 --- a/lucene/src/java/org/apache/lucene/index/CheckIndex.java +++ b/lucene/src/java/org/apache/lucene/index/CheckIndex.java @@ -661,10 +661,13 @@ public class CheckIndex { status.termCount++; final DocsEnum docs2; + final boolean hasPositions; if (postings != null) { docs2 = postings; + hasPositions = true; } else { docs2 = docs; + hasPositions = false; } int lastDoc = -1; @@ -736,22 +739,60 @@ public class CheckIndex { // Test skipping if (docFreq >= 16) { - for(int idx=0;idx<7;idx++) { - final int skipDocID = (int) (((idx+1)*(long) maxDoc)/8); - docs = terms.docs(delDocs, docs); - final int docID = docs.advance(skipDocID); - if (docID == DocsEnum.NO_MORE_DOCS) { - break; - } else { - if (docID < skipDocID) { - throw new RuntimeException("term " + term + ": advance(docID=" + skipDocID + ") returned docID=" + docID); - } - final int nextDocID = docs.nextDoc(); - if (nextDocID == DocsEnum.NO_MORE_DOCS) { + if (hasPositions) { + for(int idx=0;idx<7;idx++) { + final int skipDocID = (int) (((idx+1)*(long) maxDoc)/8); + postings = terms.docsAndPositions(delDocs, postings); + final int docID = postings.advance(skipDocID); + if (docID == DocsEnum.NO_MORE_DOCS) { break; + } else { + if (docID < skipDocID) { + throw new RuntimeException("term " + term + ": advance(docID=" + skipDocID + ") returned docID=" + docID); + } + final int freq = postings.freq(); + if (freq <= 0) { + throw new RuntimeException("termFreq " + freq + " is out of bounds"); + } + int lastPosition = -1; + for(int posUpto=0;posUpto>> 1; // shift off low bit if ((code & 1) != 0) { // if low bit is set freq = 1; // freq is one } else { + //System.out.println(" read freq"); freq = postings.readVInt(); // else read freq } posPending = freq; @@ -400,10 +403,12 @@ public class PulsingPostingsReaderImpl extends PostingsReaderBase { @Override public int advance(int target) throws IOException { + //System.out.println("PR.advance target=" + target); int doc; while((doc=nextDoc()) != NO_MORE_DOCS) { + //System.out.println(" nextDoc got doc=" + doc); if (doc >= target) { - return doc; + return docID = doc; } } return docID = NO_MORE_DOCS; @@ -411,7 +416,7 @@ public class PulsingPostingsReaderImpl extends PostingsReaderBase { @Override public int nextPosition() throws IOException { - //System.out.println("PR d&p nextPosition posPending=" + posPending + " vs freq=" + freq); + //System.out.println("PR.nextPosition posPending=" + posPending + " vs freq=" + freq); assert posPending > 0; posPending--; @@ -421,6 +426,7 @@ public class PulsingPostingsReaderImpl extends PostingsReaderBase { //System.out.println("PR skip payload=" + payloadLength); postings.skipBytes(payloadLength); } + //System.out.println(" read pos code"); final int code = postings.readVInt(); //System.out.println("PR code=" + code); if ((code & 1) != 0) { @@ -433,16 +439,17 @@ public class PulsingPostingsReaderImpl extends PostingsReaderBase { position += postings.readVInt(); } - //System.out.println("PR d&p nextPos return pos=" + position + " this=" + this); + //System.out.println(" return pos=" + position + " hasPayload=" + !payloadRetrieved + " posPending=" + posPending + " this=" + this); return position; } private void skipPositions() throws IOException { + //System.out.println("PR.skipPositions: posPending=" + posPending); while(posPending != 0) { nextPosition(); } if (storePayloads && !payloadRetrieved) { - //System.out.println(" skip payload len=" + payloadLength); + //System.out.println(" skip last payload len=" + payloadLength); postings.skipBytes(payloadLength); payloadRetrieved = true; } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsWriterImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsWriterImpl.java index 35b2a3d0278..b5b4ce728d2 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsWriterImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsWriterImpl.java @@ -201,6 +201,7 @@ public final class PulsingPostingsWriterImpl extends PostingsWriterBase { if (!omitTF) { int lastDocID = 0; int pendingIDX = 0; + int lastPayloadLength = -1; while(pendingIDX < pendingCount) { final Position doc = pending[pendingIDX]; @@ -217,7 +218,6 @@ public final class PulsingPostingsWriterImpl extends PostingsWriterBase { } int lastPos = 0; - int lastPayloadLength = -1; for(int posIDX=0;posIDX