Apache Solr open-source search software
LUCENE-3143: add IndexFileNames.isSeparateNormsFile and have SegmentMerger use it
Shai Erera7e96774437a8
diff --git a/lucene/src/java/org/apache/lucene/index/IndexFileNames.java b/lucene/src/java/org/apache/lucene/index/IndexFileNames.javaindex 405f6d21a5b..e2c10a343ca 100644--- a/lucene/src/java/org/apache/lucene/index/IndexFileNames.java+++ b/lucene/src/java/org/apache/lucene/index/IndexFileNames.java@@ -17,6 +17,8 @@ package org.apache.lucene.index;* limitations under the License.*/+import java.util.regex.Pattern;+import org.apache.lucene.index.codecs.Codec; // for javadocs/**@@ -238,5 +240,16 @@ public final class IndexFileNames {}return filename;}++ /**+ * Returns true if the given filename ends with the separate norms file+ * pattern: {@code SEPARATE_NORMS_EXTENSION + "[0-9]+"}.+ */+ public static boolean isSeparateNormsFile(String filename) {+ int idx = filename.lastIndexOf('.');+ if (idx == -1) return false;+ String ext = filename.substring(idx + 1);+ return Pattern.matches(SEPARATE_NORMS_EXTENSION + "[0-9]+", ext);+ }}diff --git a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java b/lucene/src/java/org/apache/lucene/index/SegmentMerger.javaindex 37fe85b1c4a..07d41c0ea1a 100644--- a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java+++ b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java@@ -135,8 +135,8 @@ final class SegmentMerger {for (String file : files) {assert !IndexFileNames.matchesExtension(file, IndexFileNames.DELETES_EXTENSION): ".del file is not allowed in .cfs: " + file;- assert !Pattern.matches("^.+[.]" + IndexFileNames.SEPARATE_NORMS_EXTENSION + "\\d+$", file)- : "separate norms file (.s[0-9]*) is not allowed in .cfs: " + file;+ assert !IndexFileNames.isSeparateNormsFile(file)+ : "separate norms file (.s[0-9]+) is not allowed in .cfs: " + file;cfsWriter.addFile(file);}