// Also absorb any changes to fields we had already
// seen before (eg suddenly turning on norms or
// vectors, etc.):
for(int i=0;i<numDocFields;i++) {
Fieldable field = (Fieldable) docFields.get(i);
FieldInfo fi = fieldInfos.add(field.name(), field.isIndexed(), field.isTermVectorStored(),
field.isStorePositionWithTermVector(), field.isStoreOffsetWithTermVector(),
field.getOmitNorms(), false);
if (fi.isIndexed && !fi.omitNorms) {
// Maybe grow our buffered norms
if (norms.length <= fi.number) {
int newSize = (int) ((1+fi.number)*1.25);
BufferedNorms[] newNorms = new BufferedNorms[newSize];
System.arraycopy(norms, 0, newNorms, 0, norms.length);
norms = newNorms;
}
if (norms[fi.number] == null)
norms[fi.number] = new BufferedNorms();
hasNorms = true;
}
// Make sure we have a FieldData allocated
int hashPos = fi.name.hashCode() & fieldDataHashMask;
FieldData fp = fieldDataHash[hashPos];
while(fp != null && !fp.fieldInfo.name.equals(fi.name))
fp = fp.next;
if (fp == null) {
fp = new FieldData(fi);
fp.next = fieldDataHash[hashPos];
fieldDataHash[hashPos] = fp;
if (numAllFieldData == allFieldDataArray.length) {
int newSize = (int) (allFieldDataArray.length*1.5);
int newHashSize = fieldDataHash.length*2;
FieldData newArray[] = new FieldData[newSize];
FieldData newHashArray[] = new FieldData[newHashSize];
System.arraycopy(allFieldDataArray, 0, newArray, 0, numAllFieldData);
// Rehash
fieldDataHashMask = newSize-1;
for(int j=0;j<fieldDataHash.length;j++) {
FieldData fp0 = fieldDataHash[j];
while(fp0 != null) {
hashPos = fp0.fieldInfo.name.hashCode() & fieldDataHashMask;
FieldData nextFP0 = fp0.next;
fp0.next = newHashArray[hashPos];
newHashArray[hashPos] = fp0;
fp0 = nextFP0;
}
}
allFieldDataArray = newArray;
fieldDataHash = newHashArray;
}
allFieldDataArray[numAllFieldData++] = fp;
} else {
assert fp.fieldInfo == fi;
}
if (thisFieldGen != fp.lastGen) {
// First time we're seeing this field for this doc
fp.lastGen = thisFieldGen;
fp.fieldCount = 0;
fp.doVectors = fp.doVectorPositions = fp.doVectorOffsets = false;
fp.doNorms = fi.isIndexed && !fi.omitNorms;
if (numFieldData == fieldDataArray.length) {
int newSize = fieldDataArray.length*2;
FieldData newArray[] = new FieldData[newSize];
System.arraycopy(fieldDataArray, 0, newArray, 0, numFieldData);
fieldDataArray = newArray;
}
fieldDataArray[numFieldData++] = fp;
}
if (field.isTermVectorStored()) {
if (!fp.doVectors && numVectorFields++ == vectorFieldPointers.length) {
final int newSize = (int) (numVectorFields*1.5);
vectorFieldPointers = new long[newSize];
vectorFieldNumbers = new int[newSize];
}
fp.doVectors = true;
docHasVectors = true;
fp.doVectorPositions |= field.isStorePositionWithTermVector();
fp.doVectorOffsets |= field.isStoreOffsetWithTermVector();
}
if (fp.fieldCount == fp.docFields.length) {
Fieldable[] newArray = new Fieldable[fp.docFields.length*2];
System.arraycopy(fp.docFields, 0, newArray, 0, fp.docFields.length);
fp.docFields = newArray;
}
// Lazily allocate arrays for postings:
if (field.isIndexed() && fp.postingsHash == null)
fp.initPostingArrays();
fp.docFields[fp.fieldCount++] = field;
}