LUCENE-4055: send FIS/SI to tv writer like stored fields

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4055@1341678 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-05-22 23:23:23 +00:00
parent 4b00880436
commit b1693f5cab
12 changed files with 21 additions and 19 deletions

View File

@ -35,5 +35,5 @@ public abstract class TermVectorsFormat {
/** Returns a {@link TermVectorsWriter} to write term
* vectors. */
public abstract TermVectorsWriter vectorsWriter(Directory directory, String segment, IOContext context) throws IOException;
public abstract TermVectorsWriter vectorsWriter(Directory directory, SegmentInfo segmentInfo, IOContext context) throws IOException;
}

View File

@ -90,7 +90,7 @@ public abstract class TermVectorsWriter implements Closeable {
* calls to {@link #startDocument(int)}, but a Codec should
* check that this is the case to detect the JRE bug described
* in LUCENE-1282. */
public abstract void finish(int numDocs) throws IOException;
public abstract void finish(FieldInfos fis, int numDocs) throws IOException;
/**
* Called by IndexWriter when writing new segments.
@ -159,7 +159,7 @@ public abstract class TermVectorsWriter implements Closeable {
mergeState.checkAbort.work(300);
}
}
finish(docCount);
finish(mergeState.fieldInfos, docCount);
return docCount;
}

View File

@ -75,7 +75,7 @@ class Lucene3xTermVectorsFormat extends TermVectorsFormat {
}
@Override
public TermVectorsWriter vectorsWriter(Directory directory, String segment, IOContext context) throws IOException {
public TermVectorsWriter vectorsWriter(Directory directory, SegmentInfo segmentInfo, IOContext context) throws IOException {
throw new UnsupportedOperationException("this codec can only be used for reading");
}
}

View File

@ -108,7 +108,7 @@ public class Lucene40TermVectorsFormat extends TermVectorsFormat {
}
@Override
public TermVectorsWriter vectorsWriter(Directory directory, String segment, IOContext context) throws IOException {
return new Lucene40TermVectorsWriter(directory, segment, context);
public TermVectorsWriter vectorsWriter(Directory directory, SegmentInfo segmentInfo, IOContext context) throws IOException {
return new Lucene40TermVectorsWriter(directory, segmentInfo.name, context);
}
}

View File

@ -23,6 +23,7 @@ import java.util.Comparator;
import org.apache.lucene.codecs.TermVectorsReader;
import org.apache.lucene.codecs.TermVectorsWriter;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.Fields;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.MergePolicy.MergeAbortedException;
@ -264,7 +265,7 @@ public final class Lucene40TermVectorsWriter extends TermVectorsWriter {
numDocs += copyVectorsNoDeletions(mergeState, matchingVectorsReader, reader, rawDocLengths, rawDocLengths2);
}
}
finish(numDocs);
finish(mergeState.fieldInfos, numDocs);
return numDocs;
}
@ -355,7 +356,7 @@ public final class Lucene40TermVectorsWriter extends TermVectorsWriter {
}
@Override
public void finish(int numDocs) throws IOException {
public void finish(FieldInfos fis, int numDocs) throws IOException {
if (4+((long) numDocs)*16 != tvx.getFilePointer())
// This is most likely a bug in Sun JRE 1.6.0_04/_05;
// we detect that the bug has struck, here, and

View File

@ -18,7 +18,6 @@ package org.apache.lucene.codecs.simpletext;
*/
import java.io.IOException;
import java.util.Set;
import org.apache.lucene.codecs.StoredFieldsFormat;
import org.apache.lucene.codecs.StoredFieldsReader;
@ -37,7 +36,7 @@ import org.apache.lucene.store.IOContext;
public class SimpleTextStoredFieldsFormat extends StoredFieldsFormat {
@Override
public StoredFieldsReader fieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context) throws IOException {
public StoredFieldsReader fieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context) throws IOException {;
return new SimpleTextStoredFieldsReader(directory, si, fn, context);
}

View File

@ -42,7 +42,7 @@ public class SimpleTextTermVectorsFormat extends TermVectorsFormat {
}
@Override
public TermVectorsWriter vectorsWriter(Directory directory, String segment, IOContext context) throws IOException {
return new SimpleTextTermVectorsWriter(directory, segment, context);
public TermVectorsWriter vectorsWriter(Directory directory, SegmentInfo segmentInfo, IOContext context) throws IOException {
return new SimpleTextTermVectorsWriter(directory, segmentInfo.name, context);
}
}

View File

@ -22,6 +22,7 @@ import java.util.Comparator;
import org.apache.lucene.codecs.TermVectorsWriter;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
@ -154,7 +155,7 @@ public class SimpleTextTermVectorsWriter extends TermVectorsWriter {
}
@Override
public void finish(int numDocs) throws IOException {
public void finish(FieldInfos fis, int numDocs) throws IOException {
if (numDocsWritten != numDocs) {
throw new RuntimeException("mergeVectors produced an invalid result: mergedDocs is " + numDocs + " but vec numDocs is " + numDocsWritten + " file=" + out.toString() + "; now aborting this merge to prevent index corruption");
}

View File

@ -278,7 +278,7 @@ final class SegmentMerger {
* @throws IOException
*/
private final int mergeVectors() throws IOException {
final TermVectorsWriter termVectorsWriter = codec.termVectorsFormat().vectorsWriter(directory, segment, context);
final TermVectorsWriter termVectorsWriter = codec.termVectorsFormat().vectorsWriter(directory, mergeState.segmentInfo, context);
try {
return termVectorsWriter.merge(mergeState);

View File

@ -55,7 +55,7 @@ final class TermVectorsConsumer extends TermsHashConsumer {
try {
fill(state.numDocs);
assert state.segmentInfo != null;
writer.finish(state.numDocs);
writer.finish(state.fieldInfos, state.numDocs);
} finally {
IOUtils.close(writer);
writer = null;
@ -84,7 +84,7 @@ final class TermVectorsConsumer extends TermsHashConsumer {
private final void initTermVectorsWriter() throws IOException {
if (writer == null) {
IOContext context = new IOContext(new FlushInfo(docWriter.getNumDocsInRAM(), docWriter.bytesUsed()));
writer = docWriter.codec.termVectorsFormat().vectorsWriter(docWriter.directory, docWriter.getSegmentInfo().name, context);
writer = docWriter.codec.termVectorsFormat().vectorsWriter(docWriter.directory, docWriter.getSegmentInfo(), context);
lastDocID = 0;
}
}

View File

@ -30,8 +30,8 @@ import org.apache.lucene.util.LuceneTestCase;
class PreFlexRWTermVectorsFormat extends Lucene3xTermVectorsFormat {
@Override
public TermVectorsWriter vectorsWriter(Directory directory, String segment, IOContext context) throws IOException {
return new PreFlexRWTermVectorsWriter(directory, segment, context);
public TermVectorsWriter vectorsWriter(Directory directory, SegmentInfo segmentInfo, IOContext context) throws IOException {
return new PreFlexRWTermVectorsWriter(directory, segmentInfo.name, context);
}
@Override

View File

@ -22,6 +22,7 @@ import java.util.Comparator;
import org.apache.lucene.codecs.TermVectorsWriter;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.store.DataInput;
import org.apache.lucene.store.Directory;
@ -194,7 +195,7 @@ final class PreFlexRWTermVectorsWriter extends TermVectorsWriter {
}
@Override
public void finish(int numDocs) throws IOException {
public void finish(FieldInfos fis, int numDocs) throws IOException {
if (4+((long) numDocs)*16 != tvx.getFilePointer())
// This is most likely a bug in Sun JRE 1.6.0_04/_05;
// we detect that the bug has struck, here, and