private void convert(int slot) { readerGen[slot] = currentReaderGen; int index = 0; BytesRef value = values[slot]; if (value == null) { // should already be done assert ords[slot] == NULL_ORD; return; } if (sortPos == 0 && bottomSlot != -1 && bottomSlot != slot) { // Since we are the primary sort, the entries in the // queue are bounded by bottomOrd: assert bottomOrd < termsIndex.numOrd(); if (reversed) { index = binarySearch(tempBR, termsIndex, value, bottomOrd, termsIndex.numOrd() - 1); } else { index = binarySearch(tempBR, termsIndex, value, 0, bottomOrd); } } else { // Full binary search index = binarySearch(tempBR, termsIndex, value); } if (index < 0) { index = -index - 2; } ords[slot] = index; }
public int compareBottom(int doc) { assert bottomSlot != -1; int order = termsIndex.getOrd(doc); int ord = (order == 0) ? NULL_ORD : order; final int cmp = bottomOrd - ord; if (cmp != 0) { return cmp; } // take care of the case where both vals are null if (bottomOrd == NULL_ORD) return 0; return bottomValue.compareTo(termsIndex.lookup(order, tempBR)); }
@Override public void copy(int slot, int doc) { final int ord = termsIndex.getOrd(doc); assert ord >= 0; if (ord == 0) { ords[slot] = NULL_ORD; values[slot] = null; } else { ords[slot] = ord; if (values[slot] == null) { values[slot] = new BytesRef(); } termsIndex.lookup(ord, values[slot]); } readerGen[slot] = currentReaderGen; }
@Override public void setNextReader(IndexReader reader, int docBase) throws IOException { termsIndex = FieldCache.DEFAULT.getTermsIndex(reader, field); currentReaderGen++; assert termsIndex.numOrd() > 0; if (bottomSlot != -1) { convert(bottomSlot); bottomOrd = ords[bottomSlot]; } }