@Override public int compareValues(BytesRef val1, BytesRef val2) { if (val1 == null) { if (val2 == null) { return 0; } return missingSortCmp; } else if (val2 == null) { return -missingSortCmp; } return val1.compareTo(val2); }
@Override protected boolean lessThan(TermsEnumIndex a, TermsEnumIndex b) { return a.currentTerm.compareTo(b.currentTerm) < 0; } };
@Override protected boolean lessThan(TermsEnumWithSlice termsA, TermsEnumWithSlice termsB) { return termsA.current.compareTo(termsB.current) < 0; }
@Override public int compareValues(BytesRef val1, BytesRef val2) { // missing always sorts first: if (val1 == null) { if (val2 == null) { return 0; } return missingSortCmp; } else if (val2 == null) { return -missingSortCmp; } return val1.compareTo(val2); }
@Override public int compare(int slot1, int slot2) { if (readerGen[slot1] == readerGen[slot2]) { return ords[slot1] - ords[slot2]; } final BytesRef val1 = values[slot1]; final BytesRef val2 = values[slot2]; if (val1 == null) { if (val2 == null) { return 0; } return missingSortCmp; } else if (val2 == null) { return -missingSortCmp; } return val1.compareTo(val2); }
/** Compares two terms, returning a negative integer if this term belongs before the argument, zero if this term is equal to the argument, and a positive integer if this term belongs after the argument. The ordering of terms is first by field, then by text.*/ @Override public final int compareTo(Term other) { if (field.equals(other.field)) { return bytes.compareTo(other.bytes); } else { return field.compareTo(other.field); } }
@Override public BytesRef getMax() throws IOException { BytesRef maxTerm = null; for(Terms terms : subs) { BytesRef term = terms.getMax(); if (maxTerm == null || term.compareTo(maxTerm) > 0) { maxTerm = term; } } return maxTerm; }
@Override public BytesRef getMin() throws IOException { BytesRef minTerm = null; for(Terms terms : subs) { BytesRef term = terms.getMin(); if (minTerm == null || term.compareTo(minTerm) < 0) { minTerm = term; } } return minTerm; }
@Override protected int comparePivot(int j) { get(j, k, scratch2); return pivot.compareTo(scratch2); }
private long seekTermsIndex(BytesRef text) throws IOException { long lo = 0L; long hi = (entry.termsDictSize - 1) >>> entry.termsDictIndexShift; while (lo <= hi) { final long mid = (lo + hi) >>> 1; getTermFromIndex(mid); final int cmp = term.compareTo(text); if (cmp <= 0) { lo = mid + 1; } else { hi = mid - 1; } } assert hi < 0 || getTermFromIndex(hi).compareTo(text) <= 0; assert hi == ((entry.termsDictSize - 1) >>> entry.termsDictIndexShift) || getTermFromIndex(hi + 1).compareTo(text) > 0; return hi; }
/** * Returns true if the term matches the automaton. Also stashes away the term * to assist with smart enumeration. */ @Override protected AcceptStatus accept(final BytesRef term) { if (commonSuffixRef == null || StringHelper.endsWith(term, commonSuffixRef)) { if (runAutomaton.run(term.bytes, term.offset, term.length)) return linear ? AcceptStatus.YES : AcceptStatus.YES_AND_SEEK; else return (linear && term.compareTo(linearUpperBound) < 0) ? AcceptStatus.NO : AcceptStatus.NO_AND_SEEK; } else { return (linear && term.compareTo(linearUpperBound) < 0) ? AcceptStatus.NO : AcceptStatus.NO_AND_SEEK; } }
@Override public int compareTo(ScoreTerm other) { if (this.boost == other.boost) return other.bytes.get().compareTo(this.bytes.get()); else return Float.compare(this.boost, other.boost); } }
@Override public int compare(ScoreTerm st1, ScoreTerm st2) { return st1.bytes.get().compareTo(st2.bytes.get()); } };
private long seekBlock(BytesRef text) throws IOException { long index = seekTermsIndex(text); if (index == -1L) { return -1L; } long ordLo = index << entry.termsDictIndexShift; long ordHi = Math.min(entry.termsDictSize, ordLo + (1L << entry.termsDictIndexShift)) - 1L; long blockLo = ordLo >>> entry.termsDictBlockShift; long blockHi = ordHi >>> entry.termsDictBlockShift; while (blockLo <= blockHi) { final long blockMid = (blockLo + blockHi) >>> 1; getFirstTermFromBlock(blockMid); final int cmp = term.compareTo(text); if (cmp <= 0) { blockLo = blockMid + 1; } else { blockHi = blockMid - 1; } } assert blockHi < 0 || getFirstTermFromBlock(blockHi).compareTo(text) <= 0; assert blockHi == ((entry.termsDictSize - 1) >>> entry.termsDictBlockShift) || getFirstTermFromBlock(blockHi + 1).compareTo(text) > 0; return blockHi; }
@Override protected int compare(int i, int j) { get(i, k, scratch1); get(j, k, scratch2); return scratch1.compareTo(scratch2); }
@Override public void visit(int docID, byte[] packedValue) { scratch.bytes = packedValue; while (nextQueryPoint != null) { int cmp = nextQueryPoint.compareTo(scratch); if (cmp == 0) { // Query point equals index point, so collect and return adder.add(docID); break; } else if (cmp < 0) { // Query point is before index point, so we move to next query point nextQueryPoint = iterator.next(); } else { // Query point is after index point, so we don't collect and we return: break; } } }
/** If {@code key} exists, returns its ordinal, else * returns {@code -insertionPoint-1}, like {@code * Arrays.binarySearch}. * * @param key Key to look up **/ public int lookupTerm(BytesRef key) throws IOException { int low = 0; int high = getValueCount()-1; while (low <= high) { int mid = (low + high) >>> 1; final BytesRef term = lookupOrd(mid); int cmp = term.compareTo(key); if (cmp < 0) { low = mid + 1; } else if (cmp > 0) { high = mid - 1; } else { return mid; // key found } } return -(low + 1); // key not found. }
@Override public int compareSameType(Object other) { assert exists || 0 == value.length(); MutableValueStr b = (MutableValueStr)other; int c = value.get().compareTo(b.value.get()); if (c != 0) return c; if (exists == b.exists) return 0; return exists ? 1 : -1; }
private boolean compareToLastTerm(BytesRef t) { if (lastTerm == null && t != null) { lastTerm = new BytesRefBuilder(); lastTerm.append(t); } else if (t == null) { lastTerm = null; } else { assert lastTerm.get().compareTo(t) < 0: "lastTerm=" + lastTerm + " t=" + t; lastTerm.copyBytes(t); } return true; }
@Override public void seekExact(BytesRef target, TermState otherState) { // if (DEBUG) { // System.out.println("BTTR.seekExact termState seg=" + segment + " target=" + target.utf8ToString() + " " + target + " state=" + otherState); // } assert clearEOF(); if (target.compareTo(term.get()) != 0 || !termExists) { assert otherState != null && otherState instanceof BlockTermState; currentFrame = staticFrame; currentFrame.state.copyFrom(otherState); term.copyBytes(target); currentFrame.metaDataUpto = currentFrame.getTermBlockOrd(); assert currentFrame.metaDataUpto > 0; validIndexPrefix = 0; } else { // if (DEBUG) { // System.out.println(" skip seek: already on target state=" + currentFrame.state); // } } }