LUCENE-4055: turn these into normal setters, instead asserting in indexwriter

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4055@1339053 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-05-16 08:19:49 +00:00
parent 09b10efe3f
commit 4554a4ff2f
7 changed files with 24 additions and 21 deletions

View File

@ -342,7 +342,8 @@ final class DocFieldProcessor extends DocConsumer {
}
}
DocValuesConsumer docValuesConsumer = perDocConsumer.addValuesField(valueType, fieldInfo);
fieldInfo.setDocValuesType(valueType, false);
assert fieldInfo.getDocValuesType() == null || fieldInfo.getDocValuesType() == valueType;
fieldInfo.setDocValuesType(valueType);
docValuesConsumerAndDocID = new DocValuesConsumerAndDocID(docValuesConsumer);
docValuesConsumerAndDocID.docID = docState.docID;

View File

@ -120,12 +120,8 @@ public final class FieldInfo {
assert this.indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !this.storePayloads;
}
void setDocValuesType(DocValues.Type type, boolean force) {
if (docValueType == null || force) {
docValueType = type;
} else if (type != docValueType) {
throw new IllegalArgumentException("DocValues type already set to " + docValueType + " but was: " + type);
}
void setDocValuesType(DocValues.Type type) {
docValueType = type;
}
/** @return IndexOptions for the field */
@ -162,12 +158,8 @@ public final class FieldInfo {
storePayloads = true;
}
void setNormValueType(Type type, boolean force) {
if (normType == null || force) {
normType = type;
} else if (type != normType) {
throw new IllegalArgumentException("Norm type already set to " + normType);
}
void setNormValueType(Type type) {
normType = type;
}
/**

View File

@ -33,6 +33,11 @@ public abstract class FieldInfos implements Cloneable,Iterable<FieldInfo> {
@Override
public abstract FieldInfos clone();
/**
* Return the fieldinfo object referenced by the field name
* @return the FieldInfo object or null when the given fieldName
* doesn't exist.
*/
public abstract FieldInfo fieldInfo(String fieldName);
/**
@ -43,6 +48,11 @@ public abstract class FieldInfos implements Cloneable,Iterable<FieldInfo> {
*/
public abstract FieldInfo fieldInfo(int fieldNumber);
/**
* Returns an iterator over all the fieldinfo objects present,
* ordered by ascending field number
*/
// TODO: what happens if in fact a different order is used?
public abstract Iterator<FieldInfo> iterator();
/**

View File

@ -247,10 +247,10 @@ final class MutableFieldInfos extends FieldInfos {
} else {
fi.update(isIndexed, storeTermVector, omitNorms, storePayloads, indexOptions);
if (docValues != null) {
fi.setDocValuesType(docValues, true);
fi.setDocValuesType(docValues);
}
if (normType != null) {
fi.setNormValueType(normType, true);
fi.setNormValueType(normType);
}
}
version++;

View File

@ -72,7 +72,6 @@ final class NormsConsumer extends InvertedDocEndConsumer {
} else if (fi.isIndexed()) {
anythingFlushed = true;
assert fi.getNormType() == null;
fi.setNormValueType(null, false);
}
}
}

View File

@ -69,7 +69,8 @@ final class NormsConsumerPerField extends InvertedDocEndConsumerPerField impleme
private DocValuesConsumer getConsumer(Type type) throws IOException {
if (consumer == null) {
fieldInfo.setNormValueType(type, false);
assert fieldInfo.getNormType() == null || fieldInfo.getNormType() == type;
fieldInfo.setNormValueType(type);
consumer = parent.newConsumer(docState.docWriter.newPerDocWriteState(""), fieldInfo, type);
this.initType = type;
}

View File

@ -229,21 +229,21 @@ final class SegmentMerger {
TypePromoter promoter = e.getValue();
if (promoter == null) {
if (norms) {
fi.setNormValueType(null, true);
fi.setNormValueType(null);
} else {
fi.setDocValuesType(null, true);
fi.setDocValuesType(null);
}
} else {
assert promoter != TypePromoter.getIdentityPromoter();
if (norms) {
if (fi.getNormType() != promoter.type()) {
// reset the type if we got promoted
fi.setNormValueType(promoter.type(), true);
fi.setNormValueType(promoter.type());
}
} else {
if (fi.getDocValuesType() != promoter.type()) {
// reset the type if we got promoted
fi.setDocValuesType(promoter.type(), true);
fi.setDocValuesType(promoter.type());
}
}
}