segmentName = segment;
TermInfosWriter termsOut = new TermInfosWriter(directory, segmentName, fieldInfos,
writer.getTermIndexInterval());
IndexOutput freqOut = directory.createOutput(segmentName + ".frq");
IndexOutput proxOut = directory.createOutput(segmentName + ".prx");
// Gather all FieldData's that have postings, across all
// ThreadStates
ArrayList allFields = new ArrayList();
assert allThreadsIdle();
for(int i=0;i<threadStates.length;i++) {
ThreadState state = threadStates[i];
state.trimFields();
final int numFields = state.numAllFieldData;
for(int j=0;j<numFields;j++) {
ThreadState.FieldData fp = state.allFieldDataArray[j];
if (fp.numPostings > 0)
allFields.add(fp);
}
}
// Sort by field name
Collections.sort(allFields);
final int numAllFields = allFields.size();
skipListWriter = new DefaultSkipListWriter(termsOut.skipInterval,
termsOut.maxSkipLevels,
numDocsInRAM, freqOut, proxOut);
int start = 0;
while(start < numAllFields) {
final String fieldName = ((ThreadState.FieldData) allFields.get(start)).fieldInfo.getName();
int end = start+1;
while(end < numAllFields && ((ThreadState.FieldData) allFields.get(end)).fieldInfo.getName().equals(fieldName))
end++;
ThreadState.FieldData[] fields = new ThreadState.FieldData[end-start];
for(int i=start;i<end;i++)
fields[i-start] = (ThreadState.FieldData) allFields.get(i);
// If this field has postings then add them to the
// segment
appendPostings(fields, termsOut, freqOut, proxOut);
for(int i=0;i<fields.length;i++)
fields[i].resetPostingArrays();
start = end;
}
freqOut.close();
proxOut.close();
termsOut.close();
// Record all files we have flushed
List flushedFiles = new ArrayList();
flushedFiles.add(segmentFileName(IndexFileNames.FIELD_INFOS_EXTENSION));