@Override public void finishDoc() throws IOException { if (DEBUG) System.out.println("PW finishDoc"); if (pendingCount == -1) { wrappedPostingsWriter.finishDoc(); } }
@Override public void startDoc(int docID, int termDocFreq) throws IOException { assert docID >= 0 : "got docID=" + docID; /* if (termID != -1) { if (docID == 0) { baseDocID = termID; } else if (baseDocID + docID != termID) { throw new RuntimeException("WRITE: baseDocID=" + baseDocID + " docID=" + docID + " termID=" + termID); } } */ if (DEBUG) System.out.println("PW doc=" + docID); if (pendingCount == pending.length) { push(); if (DEBUG) System.out.println("PW: wrapped.finishDoc"); wrappedPostingsWriter.finishDoc(); } if (pendingCount != -1) { assert pendingCount < pending.length; currentDoc = pending[pendingCount]; currentDoc.docID = docID; if (indexOptions == IndexOptions.DOCS_ONLY) { pendingCount++; } else if (indexOptions == IndexOptions.DOCS_AND_FREQS) { pendingCount++; currentDoc.termFreq = termDocFreq; } else { currentDoc.termFreq = termDocFreq; } } else { // We've already seen too many docs for this term -- // just forward to our fallback writer wrappedPostingsWriter.startDoc(docID, termDocFreq); } }
// Pushes pending positions to the wrapped codec private void push() throws IOException { if (DEBUG) System.out.println("PW now push @ " + pendingCount + " wrapped=" + wrappedPostingsWriter); assert pendingCount == pending.length; wrappedPostingsWriter.startTerm(); // Flush all buffered docs if (indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) { Position doc = null; for (Position pos : pending) { if (doc == null) { doc = pos; if (DEBUG) System.out.println("PW: wrapped.startDoc docID=" + doc.docID + " tf=" + doc.termFreq); wrappedPostingsWriter.startDoc(doc.docID, doc.termFreq); } else if (doc.docID != pos.docID) { assert pos.docID > doc.docID; if (DEBUG) System.out.println("PW: wrapped.finishDoc"); wrappedPostingsWriter.finishDoc(); doc = pos; if (DEBUG) System.out.println("PW: wrapped.startDoc docID=" + doc.docID + " tf=" + doc.termFreq); wrappedPostingsWriter.startDoc(doc.docID, doc.termFreq); } if (DEBUG) System.out.println("PW: wrapped.addPos pos=" + pos.pos); wrappedPostingsWriter.addPosition(pos.pos, pos.payload, pos.startOffset, pos.endOffset); } // wrappedPostingsWriter.finishDoc(); } else { for (Position doc : pending) { wrappedPostingsWriter.startDoc( doc.docID, indexOptions == IndexOptions.DOCS_ONLY ? 0 : doc.termFreq); } } pendingCount = -1; }