private int[][] ReadPositions(int skip, int numFields, PackedInts.Reader flags, PackedInts.Reader numTerms, int[] termFreqs, int flag, int totalPositions, int[][] positionIndex) { int[][] positions = new int[numFields][]; reader.Reset(vectorsStream, totalPositions); // skip int toSkip = 0; int termIndex = 0; for (int i = 0; i < skip; ++i) { int f = (int)flags.Get(i); int termCount = (int)numTerms.Get(i); if ((f & flag) != 0) { for (int j = 0; j < termCount; ++j) { int freq = termFreqs[termIndex + j]; toSkip += freq; } } termIndex += termCount; } reader.Skip(toSkip); // read doc positions for (int i = 0; i < numFields; ++i) { int f = (int)flags.Get(skip + i); int termCount = (int)numTerms.Get(skip + i); if ((f & flag) != 0) { int totalFreq = positionIndex[i][termCount]; int[] fieldPositions = new int[totalFreq]; positions[i] = fieldPositions; for (int j = 0; j < totalFreq; ) { LongsRef nextPositions = reader.Next(totalFreq - j); for (int k = 0; k < nextPositions.Length; ++k) { fieldPositions[j++] = (int)nextPositions.Longs[nextPositions.Offset + k]; } } } termIndex += termCount; } reader.Skip(totalPositions - reader.Ord()); return positions; }
// field -> term index -> position index private int[][] PositionIndex(int skip, int numFields, PackedInts.Reader numTerms, int[] termFreqs) { int[][] positionIndex = new int[numFields][]; int termIndex = 0; for (int i = 0; i < skip; ++i) { int termCount = (int)numTerms.Get(i); termIndex += termCount; } for (int i = 0; i < numFields; ++i) { int termCount = (int)numTerms.Get(skip + i); positionIndex[i] = new int[termCount + 1]; for (int j = 0; j < termCount; ++j) { int freq = termFreqs[termIndex + j]; positionIndex[i][j + 1] = positionIndex[i][j] + freq; } termIndex += termCount; } return positionIndex; }