Skip to content

Apache Lucene open-source search software

LUCENE-1008: fix corruption case when document has no term vector fields after other docs with term vector fields were added

Michael McCandless014f23033fb5
diff --git a/CHANGES.txt b/CHANGES.txt
index 82e5ed5c559..f73ae4b1ba6 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -105,6 +105,11 @@ Bug fixes
14. LUCENE-992: Fixed IndexWriter.updateDocument to be atomic again
(this was broken by LUCENE-843). (Ning Li via Mike McCandless)
+15. LUCENE-1008: Fixed corruption case when document with no term
+ vector fields is added after documents with term vector fields.
+ This bug was introduced with LUCENE-843. (Grant Ingersoll via
+ Mike McCandless)
+
New features
1. LUCENE-906: Elision filter for French.
diff --git a/src/java/org/apache/lucene/index/DocumentsWriter.java b/src/java/org/apache/lucene/index/DocumentsWriter.java
index 4e2e112e450..d3a191bcf12 100644
--- a/src/java/org/apache/lucene/index/DocumentsWriter.java
+++ b/src/java/org/apache/lucene/index/DocumentsWriter.java
@@ -552,8 +552,8 @@ final class DocumentsWriter {
// Append term vectors to the real outputs:
if (tvx != null) {
tvx.writeLong(tvd.getFilePointer());
+ tvd.writeVInt(numVectorFields);
if (numVectorFields > 0) {
- tvd.writeVInt(numVectorFields);
for(int i=0;i<numVectorFields;i++)
tvd.writeVInt(vectorFieldNumbers[i]);
assert 0 == vectorFieldPointers[0];
diff --git a/src/test/org/apache/lucene/index/TestIndexWriter.java b/src/test/org/apache/lucene/index/TestIndexWriter.java
index 5918a8b4356..5ab13ec4299 100644
--- a/src/test/org/apache/lucene/index/TestIndexWriter.java
+++ b/src/test/org/apache/lucene/index/TestIndexWriter.java
@@ -1464,7 +1464,29 @@ public class TestIndexWriter extends TestCase
dir.close();
}
-}
-
-
+ // LUCENE-1008
+ public void testNoTermVectorAfterTermVector() throws IOException {
+ MockRAMDirectory dir = new MockRAMDirectory();
+ IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(), true);
+ Document document = new Document();
+ document.add(new Field("tvtest", "a b c", Field.Store.NO, Field.Index.TOKENIZED,
+ Field.TermVector.YES));
+ iw.addDocument(document);
+ document = new Document();
+ document.add(new Field("tvtest", "x y z", Field.Store.NO, Field.Index.TOKENIZED,
+ Field.TermVector.NO));
+ iw.addDocument(document);
+ // Make first segment
+ iw.flush();
+
+ document.add(new Field("tvtest", "a b c", Field.Store.NO, Field.Index.TOKENIZED,
+ Field.TermVector.YES));
+ iw.addDocument(document);
+ // Make 2nd segment
+ iw.flush();
+ iw.optimize();
+ iw.close();
+ dir.close();
+ }
+}