/** * Append the provided bytes to this builder. */ public void append(BytesRef ref) { append(ref.bytes, ref.offset, ref.length); }
/** * Append the provided bytes to this builder. */ public void append(BytesRefBuilder builder) { append(builder.get()); }
/** * Replace the content of this builder with the provided bytes. Equivalent to * calling {@link #clear()} and then {@link #append(BytesRef)}. */ public void copyBytes(BytesRef ref) { clear(); append(ref); }
/** * Replace the content of this builder with the provided bytes. Equivalent to * calling {@link #clear()} and then {@link #append(BytesRefBuilder)}. */ public void copyBytes(BytesRefBuilder builder) { clear(); append(builder); }
/** * Replace the content of this builder with the provided bytes. Equivalent to * calling {@link #clear()} and then {@link #append(byte[], int, int)}. */ public void copyBytes(byte[] b, int off, int len) { clear(); append(b, off, len); }
@Override protected void setPivot(int i) { pivot.setLength(0); for (int o = d; o < maxLength; ++o) { final int b = byteAt(i, o); if (b == -1) { break; } pivot.append((byte) b); } }
@Override protected void setPivot(int i) { pivot.setLength(0); for (int o = k; o < maxLength; ++o) { final int b = byteAt(i, o); if (b == -1) { break; } pivot.append((byte) b); } }
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 synchronized public void add(int doc, BytesRef value) { int index = add(doc); offsets.set(index, values.length()); lengths.set(index, value.length); values.append(value); }
/** * 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(); }
scratch.append((byte) 0);
public BytesRef join(BytesRef separator, BytesRefBuilder result, BytesRef preTag, BytesRef postTag) { BytesRef[] toJoin = new BytesRef[this.candidates.length]; int len = separator.length * this.candidates.length - 1; for (int i = 0; i < toJoin.length; i++) { Candidate candidate = candidates[i]; if (preTag == null || candidate.userInput) { toJoin[i] = candidate.term; } else { final int maxLen = preTag.length + postTag.length + candidate.term.length; final BytesRefBuilder highlighted = new BytesRefBuilder();// just allocate once highlighted.grow(maxLen); if (i == 0 || candidates[i-1].userInput) { highlighted.append(preTag); } highlighted.append(candidate.term); if (toJoin.length == i + 1 || candidates[i+1].userInput) { highlighted.append(postTag); } toJoin[i] = highlighted.get(); } len += toJoin[i].length; } result.grow(len); return WordScorer.join(separator, result, toJoin); }
@Override public BytesRef nextValue() throws IOException { BytesRef nextID = idValues.nextValue(); scratch.copyBytes(prefix); scratch.append(nextID); return scratch.get(); }
@Override public BytesRef toBytesRef() { BytesRefBuilder builder = new BytesRefBuilder(); builder.grow(length()); BytesRef spare; BytesRefIterator iterator = iterator(); try { while ((spare = iterator.next()) != null) { builder.append(spare); } } catch (IOException ex) { throw new AssertionError("won't happen", ex); // this is really an error since we don't do IO in our bytesreferences } return builder.toBytesRef(); }
public void finishTerm(long defaultWeight) throws IOException { ArrayUtil.timSort(surfaceFormsAndPayload, 0, count); int deduplicator = 0; analyzed.append((byte) 0); analyzed.setLength(analyzed.length() + 1); analyzed.grow(analyzed.length()); for (int i = 0; i < count; i++) { analyzed.setByteAt(analyzed.length() - 1, (byte) deduplicator++); Util.toIntsRef(analyzed.get(), scratchInts); SurfaceFormAndPayload candiate = surfaceFormsAndPayload[i]; long cost = candiate.weight == -1 ? encodeWeight(Math.min(Integer.MAX_VALUE, defaultWeight)) : candiate.weight; builder.add(scratchInts.get(), outputs.newPair(cost, candiate.payload)); } seenSurfaceForms.clear(); count = 0; }