/** Creates a new TermsEnum over the provided values */ public SortedDocValuesTermsEnum(SortedDocValues values) { this.values = values; scratch = new BytesRefBuilder(); }
/** Creates a new TermsEnum over the provided values */ public SortedSetDocValuesTermsEnum(SortedSetDocValues values) { this.values = values; scratch = new BytesRefBuilder(); }
private final BytesRefBuilder pivot = new BytesRefBuilder(); };
private final BytesRefBuilder pivot = new BytesRefBuilder(); };
public BinaryDocValuesFieldUpdates(long delGen, String field, int maxDoc) { super(maxDoc, delGen, field, DocValuesType.BINARY); offsets = new PagedGrowableWriter(1, PAGE_SIZE, 1, PackedInts.FAST); lengths = new PagedGrowableWriter(1, PAGE_SIZE, 1, PackedInts.FAST); values = new BytesRefBuilder(); }
BufferedBinaryDocValues(PackedLongValues lengths, int maxLength, DataInput bytesIterator, DocIdSetIterator docsWithFields) { this.value = new BytesRefBuilder(); this.value.grow(maxLength); this.lengthsIterator = lengths.iterator(); this.bytesIterator = bytesIterator; this.docsWithField = docsWithFields; }
private BytesRef convertNumber(Number number) { if (Integer.class.isInstance(number) || Byte.class.isInstance(number) || Short.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); NumericUtils.intToPrefixCoded(number.intValue(), 0, ref); return ref.get(); } else if (Double.class.isInstance(number) || BigDecimal.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); long l = NumericUtils.doubleToSortableLong(number.doubleValue()); NumericUtils.longToPrefixCoded(l, 0, ref); return ref.get(); } else if (Long.class.isInstance(number) || BigInteger.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(number.longValue(), 0, ref); return ref.get(); } else if (Float.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); int i = NumericUtils.floatToSortableInt(number.floatValue()); NumericUtils.intToPrefixCoded(i, 0, ref); return ref.get(); } else { throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName()); } }
@Override public CharTermAttributeImpl clone() { CharTermAttributeImpl t = (CharTermAttributeImpl)super.clone(); // Do a deep clone t.termBuffer = new char[this.termLength]; System.arraycopy(this.termBuffer, 0, t.termBuffer, 0, this.termLength); t.builder = new BytesRefBuilder(); t.builder.copyBytes(builder.get()); return t; }
/** * return an automata-based enum for matching up to editDistance from * lastTerm, if possible */ private TermsEnum getAutomatonEnum(int editDistance, BytesRef lastTerm) throws IOException { assert editDistance < automata.length; final CompiledAutomaton compiled = automata[editDistance]; BytesRef initialSeekTerm; if (lastTerm == null) { // This is the first enum we are pulling: initialSeekTerm = null; } else { // We are pulling this enum (e.g., ed=1) after iterating for a while already (e.g., ed=2): initialSeekTerm = compiled.floor(lastTerm, new BytesRefBuilder()); } return terms.intersect(compiled, initialSeekTerm); }
private final BytesRef scratchBytes1 = new BytesRef(); private final BytesRef scratchBytes2 = new BytesRef(); private final BytesRefBuilder pivotBuilder = new BytesRefBuilder(); private final BytesRefBuilder scratch1 = new BytesRefBuilder(); private final BytesRefBuilder scratch2 = new BytesRefBuilder(); }.sort(0, size()); return orderedEntries;
@Override public void copy(int slot, int doc) throws IOException { final BytesRef comparableBytes = getValueForDoc(doc); if (comparableBytes == null) { values[slot] = null; } else { if (tempBRs[slot] == null) { tempBRs[slot] = new BytesRefBuilder(); } tempBRs[slot].copyBytes(comparableBytes); values[slot] = tempBRs[slot].get(); } }
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; }
/** * Returns the longest BytesRef that is a prefix of all accepted strings and * visits each state at most once. The automaton must be deterministic. * * @return common prefix, which can be an empty (length 0) BytesRef (never null) */ public static BytesRef getCommonPrefixBytesRef(Automaton a) { BytesRefBuilder builder = new BytesRefBuilder(); HashSet<Integer> visited = new HashSet<>(); int s = 0; boolean done; Transition t = new Transition(); do { done = true; visited.add(s); if (a.isAccept(s) == false && a.getNumTransitions(s) == 1) { a.getTransition(s, 0, t); if (t.min == t.max && !visited.contains(t.dest)) { builder.append((byte) t.min); s = t.dest; done = false; } } } while (!done); return builder.get(); }
/** Return an array that contains the min and max values for the [offset, offset+length] interval * of the given {@link BytesRef}s. */ private static BytesRef[] computeMinMax(int count, IntFunction<BytesRef> packedValues, int offset, int length) { assert length > 0; BytesRefBuilder min = new BytesRefBuilder(); BytesRefBuilder max = new BytesRefBuilder(); BytesRef first = packedValues.apply(0); min.copyBytes(first.bytes, first.offset + offset, length); max.copyBytes(first.bytes, first.offset + offset, length); for (int i = 1; i < count; ++i) { BytesRef candidate = packedValues.apply(i); if (FutureArrays.compareUnsigned(min.bytes(), 0, length, candidate.bytes, candidate.offset + offset, candidate.offset + offset + length) > 0) { min.copyBytes(candidate.bytes, candidate.offset + offset, length); } else if (FutureArrays.compareUnsigned(max.bytes(), 0, length, candidate.bytes, candidate.offset + offset, candidate.offset + offset + length) < 0) { max.copyBytes(candidate.bytes, candidate.offset + offset, length); } } return new BytesRef[]{min.get(), max.get()}; }
@Override public void copy(int slot, int doc) throws IOException { int ord = getOrdForDoc(doc); if (ord == -1) { ord = missingOrd; values[slot] = null; } else { assert ord >= 0; if (tempBRs[slot] == null) { tempBRs[slot] = new BytesRefBuilder(); } tempBRs[slot].copyBytes(termsIndex.lookupOrd(ord)); values[slot] = tempBRs[slot].get(); } ords[slot] = ord; readerGen[slot] = currentReaderGen; }
final BytesRefBuilder spare = new BytesRefBuilder(); final BytesRef result = new BytesRef(); final int size = size();
previous = new BytesRefBuilder(); } else { int cmp = previous.get().compareTo(current);
/** * Creates a new {@link TermInSetQuery} from the given collection of terms. */ public TermInSetQuery(String field, Collection<BytesRef> terms) { BytesRef[] sortedTerms = terms.toArray(new BytesRef[terms.size()]); // already sorted if we are a SortedSet with natural order boolean sorted = terms instanceof SortedSet && ((SortedSet<BytesRef>)terms).comparator() == null; if (!sorted) { ArrayUtil.timSort(sortedTerms); } PrefixCodedTerms.Builder builder = new PrefixCodedTerms.Builder(); BytesRefBuilder previous = null; for (BytesRef term : sortedTerms) { if (previous == null) { previous = new BytesRefBuilder(); } else if (previous.get().equals(term)) { continue; // deduplicate } builder.add(field, term); previous.copyBytes(term); } this.field = field; termData = builder.finish(); termDataHashCode = termData.hashCode(); }
DirectMonotonicWriter writer = DirectMonotonicWriter.getInstance(meta, addressBuffer, numBlocks, DIRECT_MONOTONIC_BLOCK_SHIFT); BytesRefBuilder previous = new BytesRefBuilder(); long ord = 0; long start = data.getFilePointer();
BytesRefBuilder previous = new BytesRefBuilder(); long offset = 0; long ord = 0;