}
} else {
final CompressingStoredFieldsIndexReader index = matchingVectorsReader.getIndex();
final IndexInput vectorsStreamOrig = matchingVectorsReader.getVectorsStream();
vectorsStreamOrig.seek(0);
final ChecksumIndexInput vectorsStream = new BufferedChecksumIndexInput(vectorsStreamOrig.clone());
for (int i = nextLiveDoc(0, liveDocs, maxDoc); i < maxDoc; ) {
// We make sure to move the checksum input in any case, otherwise the final
// integrity check might need to read the whole file a second time
final long startPointer = index.getStartPointer(i);
if (startPointer > vectorsStream.getFilePointer()) {
vectorsStream.seek(startPointer);
}
if (pendingDocs.isEmpty()
&& (i == 0 || index.getStartPointer(i - 1) < startPointer)) { // start of a chunk
final int docBase = vectorsStream.readVInt();
final int chunkDocs = vectorsStream.readVInt();
assert docBase + chunkDocs <= matchingSegmentReader.maxDoc();
if (docBase + chunkDocs < matchingSegmentReader.maxDoc()
&& nextDeletedDoc(docBase, liveDocs, docBase + chunkDocs) == docBase + chunkDocs) {
final long chunkEnd = index.getStartPointer(docBase + chunkDocs);
final long chunkLength = chunkEnd - vectorsStream.getFilePointer();
indexWriter.writeIndex(chunkDocs, this.vectorsStream.getFilePointer());
this.vectorsStream.writeVInt(docCount);
this.vectorsStream.writeVInt(chunkDocs);
this.vectorsStream.copyBytes(vectorsStream, chunkLength);
docCount += chunkDocs;
this.numDocs += chunkDocs;
mergeState.checkAbort.work(300 * chunkDocs);
i = nextLiveDoc(docBase + chunkDocs, liveDocs, maxDoc);
} else {
for (; i < docBase + chunkDocs; i = nextLiveDoc(i + 1, liveDocs, maxDoc)) {
final Fields vectors = reader.getTermVectors(i);
addAllDocVectors(vectors, mergeState);
++docCount;
mergeState.checkAbort.work(300);
}
}
} else {
final Fields vectors = reader.getTermVectors(i);
addAllDocVectors(vectors, mergeState);
++docCount;
mergeState.checkAbort.work(300);
i = nextLiveDoc(i + 1, liveDocs, maxDoc);
}
}
vectorsStream.seek(vectorsStream.length() - CodecUtil.footerLength());
CodecUtil.checkFooter(vectorsStream);
}
}
finish(mergeState.fieldInfos, docCount);
return docCount;