hasPos = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) > 0;
hasOffsets = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) > 0;
hasPayloads = fieldInfo.hasPayloads();
BytesRef term;
DocsEnum docsEnum = null;
DocsAndPositionsEnum docsAndPositionsEnum = null;
final TermsEnum termsEnum = termsIn.iterator(null);
int termOffset = 0;
final IntArrayWriter scratch = new IntArrayWriter();
// Used for payloads, if any:
final RAMOutputStream ros = new RAMOutputStream();
// if (DEBUG) {
// System.out.println("\nLOAD terms seg=" + state.segmentInfo.name + " field=" + field + " hasOffsets=" + hasOffsets + " hasFreq=" + hasFreq + " hasPos=" + hasPos + " hasPayloads=" + hasPayloads);
// }
while ((term = termsEnum.next()) != null) {
final int docFreq = termsEnum.docFreq();
final long totalTermFreq = termsEnum.totalTermFreq();
// if (DEBUG) {
// System.out.println(" term=" + term.utf8ToString());
// }
termOffsets[count] = termOffset;
if (termBytes.length < (termOffset + term.length)) {
termBytes = ArrayUtil.grow(termBytes, termOffset + term.length);
}
System.arraycopy(term.bytes, term.offset, termBytes, termOffset, term.length);
termOffset += term.length;
termOffsets[count+1] = termOffset;
if (hasPos) {
docsAndPositionsEnum = termsEnum.docsAndPositions(null, docsAndPositionsEnum);
} else {
docsEnum = termsEnum.docs(null, docsEnum);
}
final TermAndSkip ent;
final DocsEnum docsEnum2;
if (hasPos) {
docsEnum2 = docsAndPositionsEnum;
} else {
docsEnum2 = docsEnum;
}
int docID;
if (docFreq <= lowFreqCutoff) {
ros.reset();
// Pack postings for low-freq terms into a single int[]:
while ((docID = docsEnum2.nextDoc()) != DocsEnum.NO_MORE_DOCS) {
scratch.add(docID);
if (hasFreq) {
final int freq = docsEnum2.freq();
scratch.add(freq);
if (hasPos) {
for(int pos=0;pos<freq;pos++) {
scratch.add(docsAndPositionsEnum.nextPosition());
if (hasOffsets) {
scratch.add(docsAndPositionsEnum.startOffset());
scratch.add(docsAndPositionsEnum.endOffset());
}
if (hasPayloads) {
final BytesRef payload = docsAndPositionsEnum.getPayload();
if (payload != null) {
scratch.add(payload.length);
ros.writeBytes(payload.bytes, payload.offset, payload.length);
} else {
scratch.add(0);
}
}
}
}
}
}
final byte[] payloads;
if (hasPayloads) {
ros.flush();
payloads = new byte[(int) ros.length()];
ros.writeTo(payloads, 0);
} else {
payloads = null;
}
final int[] postings = scratch.get();
ent = new LowFreqTerm(postings, payloads, docFreq, (int) totalTermFreq);
} else {
final int[] docs = new int[docFreq];
final int[] freqs;
final int[][] positions;
final byte[][][] payloads;
if (hasFreq) {
freqs = new int[docFreq];
if (hasPos) {
positions = new int[docFreq][];
if (hasPayloads) {
payloads = new byte[docFreq][][];
} else {
payloads = null;
}
} else {
positions = null;
payloads = null;
}
} else {
freqs = null;
positions = null;
payloads = null;
}
// Use separate int[] for the postings for high-freq
// terms:
int upto = 0;
while ((docID = docsEnum2.nextDoc()) != DocsEnum.NO_MORE_DOCS) {
docs[upto] = docID;
if (hasFreq) {
final int freq = docsEnum2.freq();
freqs[upto] = freq;
if (hasPos) {
final int mult;
if (hasOffsets) {
mult = 3;