Apache Solr open-source search software
LUCENE-3012: if you use setNorm, lucene writes a headerless separate norms file
Robert Muir731e619a7c34
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 2368db614f9..04b52168971 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -564,6 +564,9 @@ Bug fixesPhraseQuery as term with lower doc freq will also have less positions.(Uwe Schindler, Robert Muir, Otis Gospodnetic)+* LUCENE-3012: Lucene writes the header now for separate norm files (*.sNNN)+ (Robert Muir)+Test Cases* LUCENE-3002: added 'tests.iter.min' to control 'tests.iter' by allowing todiff --git a/lucene/src/java/org/apache/lucene/index/SegmentReader.java b/lucene/src/java/org/apache/lucene/index/SegmentReader.javaindex aa97da86d47..ec045c416f5 100644--- a/lucene/src/java/org/apache/lucene/index/SegmentReader.java+++ b/lucene/src/java/org/apache/lucene/index/SegmentReader.java@@ -38,6 +38,7 @@ import org.apache.lucene.util.BitVector;import org.apache.lucene.util.Bits;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.CloseableThreadLocal;+import org.apache.lucene.util.StringHelper;/*** @lucene.experimental@@ -441,6 +442,7 @@ public class SegmentReader extends IndexReader implements Cloneable {boolean success = false;try {try {+ out.writeBytes(SegmentMerger.NORMS_HEADER, 0, SegmentMerger.NORMS_HEADER.length);out.writeBytes(bytes, maxDoc());} finally {out.close();@@ -986,8 +988,20 @@ public class SegmentReader extends IndexReader implements Cloneable {// If this were to change in the future, a clone could be done here.normInput = singleNormStream;} else {- normSeek = 0;normInput = d.openInput(fileName);+ // if the segment was created in 3.2 or after, we wrote the header for sure,+ // and don't need to do the sketchy file size check. otherwise, we check+ // if the size is exactly equal to maxDoc to detect a headerless file.+ // NOTE: remove this check in Lucene 5.0!+ String version = si.getVersion();+ final boolean isUnversioned =+ (version == null || StringHelper.getVersionComparator().compare(version, "3.2") < 0)+ && normInput.length() == maxDoc();+ if (isUnversioned) {+ normSeek = 0;+ } else {+ normSeek = SegmentMerger.NORMS_HEADER.length;+ }}norms.put(fi.name, new Norm(normInput, fi.number, normSeek));diff --git a/lucene/src/test/org/apache/lucene/index/index.32.cfs.zip b/lucene/src/test/org/apache/lucene/index/index.32.cfs.zipindex 52939839d69..eff3153eb2a 100644Binary files a/lucene/src/test/org/apache/lucene/index/index.32.cfs.zip and b/lucene/src/test/org/apache/lucene/index/index.32.cfs.zip differdiff --git a/lucene/src/test/org/apache/lucene/index/index.32.nocfs.zip b/lucene/src/test/org/apache/lucene/index/index.32.nocfs.zipindex c32fbd68949..0b345da695b 100644Binary files a/lucene/src/test/org/apache/lucene/index/index.32.nocfs.zip and b/lucene/src/test/org/apache/lucene/index/index.32.nocfs.zip differ