Apache Lucene open-source search software
LUCENE-2811: switch version numbers on trunk due to 3.x index format change; fix hasVectors check to work correctly when doc stores are compound file
Michael McCandless66b2c016b009
diff --git a/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java b/lucene/src/java/org/apache/lucene/index/DocumentsWriter.javaindex 4389a7579b0..dffbe3bfe3b 100644--- a/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java+++ b/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java@@ -727,13 +727,11 @@ final class DocumentsWriter {newSegment.setDocStoreOffset(docStoreOffset);}- boolean hasVectors = false;-if (closeDocStore) {closeDocStore(flushState, writer, deleter, newSegment, mergePolicy, segmentInfos);}- hasVectors |= flushState.hasVectors;+ boolean hasVectors = flushState.hasVectors;if (numDocsInRAM > 0) {diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.javaindex 245215530f2..61d9e9a7598 100644--- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java@@ -2719,8 +2719,6 @@ public class IndexWriter implements Closeable {// format as well:setMergeDocStoreIsCompoundFile(merge);- merge.info.setHasProx(merger.fieldInfos().hasProx());-segmentInfos.subList(start, start + merge.segments.size()).clear();assert !segmentInfos.contains(merge.info);segmentInfos.add(start, merge.info);diff --git a/lucene/src/java/org/apache/lucene/index/SegmentInfo.java b/lucene/src/java/org/apache/lucene/index/SegmentInfo.javaindex d88bba82e58..f1ec386ff80 100644--- a/lucene/src/java/org/apache/lucene/index/SegmentInfo.java+++ b/lucene/src/java/org/apache/lucene/index/SegmentInfo.java@@ -116,6 +116,7 @@ public final class SegmentInfo {docStoreOffset = src.docStoreOffset;docStoreIsCompoundFile = src.docStoreIsCompoundFile;hasVectors = src.hasVectors;+ hasProx = src.hasProx;if (src.normGen == null) {normGen = null;} else {@@ -194,12 +195,30 @@ public final class SegmentInfo {hasVectors = input.readByte() == 1;} else {final String storesSegment;+ final String ext;+ final boolean isCompoundFile;if (docStoreOffset != -1) {storesSegment = docStoreSegment;+ isCompoundFile = docStoreIsCompoundFile;+ ext = IndexFileNames.COMPOUND_FILE_STORE_EXTENSION;} else {storesSegment = name;+ isCompoundFile = getUseCompoundFile();+ ext = IndexFileNames.COMPOUND_FILE_EXTENSION;+ }+ final Directory dirToTest;+ if (isCompoundFile) {+ dirToTest = new CompoundFileReader(dir, IndexFileNames.segmentFileName(storesSegment, "", ext));+ } else {+ dirToTest = dir;+ }+ try {+ hasVectors = dirToTest.fileExists(IndexFileNames.segmentFileName(storesSegment, "", IndexFileNames.VECTORS_INDEX_EXTENSION));+ } finally {+ if (isCompoundFile) {+ dirToTest.close();+ }}- hasVectors = dir.fileExists(IndexFileNames.segmentFileName(storesSegment, "", IndexFileNames.VECTORS_INDEX_EXTENSION));}}diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java b/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.javaindex 3157feba7bd..ea402d9585f 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java@@ -37,14 +37,14 @@ public class DefaultSegmentInfosWriter extends SegmentInfosWriter {/** Each segment records whether its postings are written* in the new flex format */- public static final int FORMAT_4_0 = -10;+ public static final int FORMAT_4_0 = -11;/** Each segment records whether it has term vectors */- public static final int FORMAT_HAS_VECTORS = -11;+ public static final int FORMAT_HAS_VECTORS = -10;/** This must always point to the most recent file format.* whenever you add a new format, make it 1 smaller (negative version logic)! */- public static final int FORMAT_CURRENT = FORMAT_HAS_VECTORS;+ public static final int FORMAT_CURRENT = FORMAT_4_0;/** This must always point to the first supported file format. */public static final int FORMAT_MINIMUM = FORMAT_DIAGNOSTICS;diff --git a/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.javaindex 14a5a920f90..b017d97eb00 100644--- a/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java+++ b/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java@@ -344,6 +344,10 @@ public class TestBackwardsCompatibility extends LuceneTestCase {f = d.getField("fie\u2C77ld");assertEquals("field with non-ascii name", f.stringValue());}++ TermFreqVector tfv = reader.getTermFreqVector(i, "utf8");+ assertNotNull("docID=" + i + " index=" + dirName, tfv);+ assertTrue(tfv instanceof TermPositionVector);} else// Only ID 7 is deletedassertEquals(7, i);diff --git a/lucene/src/test/org/apache/lucene/index/index.31.cfs.zip b/lucene/src/test/org/apache/lucene/index/index.31.cfs.zipindex c2cdb53bdbd..02eac457956 100644Binary files a/lucene/src/test/org/apache/lucene/index/index.31.cfs.zip and b/lucene/src/test/org/apache/lucene/index/index.31.cfs.zip differdiff --git a/lucene/src/test/org/apache/lucene/index/index.31.nocfs.zip b/lucene/src/test/org/apache/lucene/index/index.31.nocfs.zipindex fc05c754a1f..47af2bfe3a1 100644Binary files a/lucene/src/test/org/apache/lucene/index/index.31.nocfs.zip and b/lucene/src/test/org/apache/lucene/index/index.31.nocfs.zip differ