1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| void loadBlock() throws IOException {
// Clone the IndexInput lazily, so that consumers // that just pull a TermsEnum to // seekExact(TermState) don't pay this cost: ste.initIndexInput();
if (nextEnt != -1) { // Already loaded return; } // System.out.println("blc=" + blockLoadCount);
ste.in.seek(fp); int code = ste.in.readVInt(); entCount = code >>> 1; assert entCount > 0; isLastInFloor = (code & 1) != 0;
assert arc == null || (isLastInFloor || isFloor) : "fp=" + fp + " arc=" + arc + " isFloor=" + isFloor + " isLastInFloor=" + isLastInFloor;
// TODO: if suffixes were stored in random-access // array structure, then we could do binary search // instead of linear scan to find target term; eg // we could have simple array of offsets
final long startSuffixFP = ste.in.getFilePointer(); // term suffixes: final long codeL = ste.in.readVLong(); isLeafBlock = (codeL & 0x04) != 0; final int numSuffixBytes = (int) (codeL >>> 3); if (suffixBytes.length < numSuffixBytes) { suffixBytes = new byte[ArrayUtil.oversize(numSuffixBytes, 1)]; } try { compressionAlg = CompressionAlgorithm.byCode((int) codeL & 0x03); } catch (IllegalArgumentException e) { throw new CorruptIndexException(e.getMessage(), ste.in, e); } compressionAlg.read(ste.in, suffixBytes, numSuffixBytes); suffixesReader.reset(suffixBytes, 0, numSuffixBytes);
int numSuffixLengthBytes = ste.in.readVInt(); final boolean allEqual = (numSuffixLengthBytes & 0x01) != 0; numSuffixLengthBytes >>>= 1; if (suffixLengthBytes.length < numSuffixLengthBytes) { suffixLengthBytes = new byte[ArrayUtil.oversize(numSuffixLengthBytes, 1)]; } if (allEqual) { Arrays.fill(suffixLengthBytes, 0, numSuffixLengthBytes, ste.in.readByte()); } else { ste.in.readBytes(suffixLengthBytes, 0, numSuffixLengthBytes); } suffixLengthsReader.reset(suffixLengthBytes, 0, numSuffixLengthBytes); totalSuffixBytes = ste.in.getFilePointer() - startSuffixFP;
/*if (DEBUG) { if (arc == null) { System.out.println(" loadBlock (next) fp=" + fp + " entCount=" + entCount + " prefixLen=" + prefix + " isLastInFloor=" + isLastInFloor + " leaf?=" + isLeafBlock); } else { System.out.println(" loadBlock (seek) fp=" + fp + " entCount=" + entCount + " prefixLen=" + prefix + " hasTerms?=" + hasTerms + " isFloor?=" + isFloor + " isLastInFloor=" + isLastInFloor + " leaf?=" + isLeafBlock); } }*/
// stats int numBytes = ste.in.readVInt(); if (statBytes.length < numBytes) { statBytes = new byte[ArrayUtil.oversize(numBytes, 1)]; } ste.in.readBytes(statBytes, 0, numBytes); statsReader.reset(statBytes, 0, numBytes); statsSingletonRunLength = 0; metaDataUpto = 0;
state.termBlockOrd = 0; nextEnt = 0; lastSubFP = -1;
// TODO: we could skip this if !hasTerms; but // that's rare so won't help much // metadata numBytes = ste.in.readVInt(); if (bytes.length < numBytes) { bytes = new byte[ArrayUtil.oversize(numBytes, 1)]; } ste.in.readBytes(bytes, 0, numBytes); bytesReader.reset(bytes, 0, numBytes);
// Sub-blocks of a single floor block are always // written one after another -- tail recurse: fpEnd = ste.in.getFilePointer(); // if (DEBUG) { // System.out.println(" fpEnd=" + fpEnd); // } }
|