Apache Lucene open-source search software
move normDVType checking into FieldInfo; add nocommits
Michael McCandless7e683d8ed072
diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfo.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfo.javaindex cda6d56f100..e614ba05e1f 100644--- a/lucene/core/src/java/org/apache/lucene/index/FieldInfo.java+++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfo.java@@ -232,6 +232,9 @@ public final class FieldInfo {// nocommit type is always number? should we remove this?void setNormValueType(DocValuesType type) {+ if (normType != null && normType != type) {+ throw new IllegalArgumentException("cannot change Norm type from " + normType + " to " + type + " for field \"" + name + "\"");+ }normType = type;assert checkConsistency();}diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.javaindex 9384338f548..be18ffe1d03 100644--- a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java+++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java@@ -213,15 +213,17 @@ public class FieldInfos implements Iterable<FieldInfo> {* Sets the given field number and name if not yet set.*/// nocommit: why is docvalues involved with global field numbers?+ // nocommit: and is it even tested...synchronized void setIfNotSet(int fieldNumber, String fieldName, DocValuesType dvType) {final Integer boxedFieldNumber = Integer.valueOf(fieldNumber);if (!numberToName.containsKey(boxedFieldNumber)&& !nameToNumber.containsKey(fieldName)- && !docValuesType.containsKey(fieldName)) {+ && !docValuesType.containsKey(dvType)) {numberToName.put(boxedFieldNumber, fieldName);nameToNumber.put(fieldName, boxedFieldNumber);docValuesType.put(fieldName, dvType);} else {+ // nocommit should this be a real check?assert containsConsistent(boxedFieldNumber, fieldName, dvType);}}@@ -319,22 +321,10 @@ public class FieldInfos implements Iterable<FieldInfo> {fi.update(isIndexed, storeTermVector, omitNorms, storePayloads, indexOptions);if (docValues != null) {- DocValuesType currentDVType = fi.getDocValuesType();- if (currentDVType == null) {- fi.setDocValuesType(docValues);- } else if (currentDVType != docValues) {- throw new IllegalArgumentException("cannot change DocValues type from " + currentDVType + " to " + docValues + " for field \"" + name + "\"");- }fi.setDocValuesType(docValues);}if (!fi.omitsNorms() && normType != null) {- DocValuesType currentDVType = fi.getNormType();- if (currentDVType == null) {- fi.setNormValueType(docValues);- } else if (currentDVType != normType) {- throw new IllegalArgumentException("cannot change Norm type from " + currentDVType + " to " + normType + " for field \"" + name + "\"");- }fi.setNormValueType(normType);}}diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.javaindex 1da8087a382..318486e82ea 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java@@ -763,6 +763,8 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {private FieldNumbers getFieldNumberMap() throws IOException {final FieldNumbers map = new FieldNumbers();+ // nocommit for a 4.0 index that has inconsistent DV+ // types ... this will throw exc on init of IW?for(SegmentInfoPerCommit info : segmentInfos) {for(FieldInfo fi : getFieldInfos(info.info)) {map.addOrGet(fi.name, fi.number, fi.getDocValuesType());