@Override public long seek(long ord) { long idx = ord / indexInterval; // caller must ensure ord is in bounds assert idx < fieldIndex.numIndexTerms; final long offset = fieldIndex.termOffsets.get(idx); final int length = (int) (fieldIndex.termOffsets.get(1+idx) - offset); termBytesReader.fillSlice(term, fieldIndex.termBytesStart + offset, length); this.ord = idx * indexInterval; return fieldIndex.termsStart + fieldIndex.termsDictOffsets.get(idx); } }
@Override public long next() { final long idx = 1 + (ord / indexInterval); if (idx >= fieldIndex.numIndexTerms) { return -1; } ord += indexInterval; final long offset = fieldIndex.termOffsets.get(idx); final int length = (int) (fieldIndex.termOffsets.get(1+idx) - offset); termBytesReader.fillSlice(term, fieldIndex.termBytesStart + offset, length); return fieldIndex.termsStart + fieldIndex.termsDictOffsets.get(idx); }
@Override public BytesRef get(long id) { long startAddress = bytes.offset + addresses.get(id); long endAddress = bytes.offset + addresses.get(id+1); int length = (int) (endAddress - startAddress); try { data.seek(startAddress); data.readBytes(term.bytes, 0, length); term.length = length; return term; } catch (IOException e) { throw new RuntimeException(e); } } };
@Override public BytesRef get(long id) { long startAddress = addresses.get(id); long endAddress = addresses.get(id+1); int length = (int) (endAddress - startAddress); try { data.seek(startAddress); data.readBytes(buffer, 0, length); term.length = length; return term; } catch (IOException e) { throw new RuntimeException(e); } } };
@Override public void seekExact(long ord) throws IOException { long block = ord / interval; if (ord >= currentOrd && block == currentOrd / interval) { // seek within current block } else { // position before start of block currentOrd = ord - ord % interval - 1; input.seek(bytes.offset + addresses.get(block)); } while (currentOrd < ord) { next(); } }
@Override public void seekExact(long ord) throws IOException { long block = ord / interval; if (ord >= currentOrd && block == currentOrd / interval) { // seek within current block } else { // position before start of block currentOrd = ord - ord % interval - 1; input.seek(bytes.offset + addresses.get(block)); } while (currentOrd < ord) { next(); } }
long binarySearchIndex(BytesRef text) throws IOException { long low = 0; long high = numReverseIndexValues - 1; while (low <= high) { long mid = (low + high) >>> 1; reverseTerms.fill(scratch, reverseAddresses.get(mid)); int cmp = scratch.compareTo(text); if (cmp < 0) { low = mid + 1; } else if (cmp > 0) { high = mid - 1; } else { return mid; } } return high; }
long binarySearchBlock(BytesRef text, long low, long high) throws IOException { while (low <= high) { long mid = (low + high) >>> 1; input.seek(addresses.get(mid)); term.length = input.readVInt(); input.readBytes(term.bytes, 0, term.length); int cmp = term.compareTo(text); if (cmp < 0) { low = mid + 1; } else if (cmp > 0) { high = mid - 1; } else { return mid; } } return high; }
long binarySearchBlock(BytesRef text, long low, long high) throws IOException { while (low <= high) { long mid = (low + high) >>> 1; input.seek(addresses.get(mid)); term.length = input.readVInt(); input.readBytes(term.bytes, 0, term.length); int cmp = term.compareTo(text); if (cmp < 0) { low = mid + 1; } else if (cmp > 0) { high = mid - 1; } else { return mid; } } return high; }
@Override public void seekExact(long ord) throws IOException { long block = ord >>> INTERVAL_SHIFT; if (block != currentOrd >>> INTERVAL_SHIFT) { // switch to different block input.seek(addresses.get(block)); readHeader(); } currentOrd = ord; int offset = (int) (ord & INTERVAL_MASK); if (offset == 0) { readFirstTerm(); } else { input.seek(currentBlockStart + offsets[offset-1]); readTerm(offset); } }