@Override public BytesRef get() { return new BytesRef(array); }
/** * Returns a shallow clone of this instance (the underlying bytes are * <b>not</b> copied and will be shared by both the returned object and this * object. * * @see #deepCopyOf */ @Override public BytesRef clone() { return new BytesRef(bytes, offset, length); }
/** Constructs a Term with the given field and empty text. * This serves two purposes: 1) reuse of a Term with the same field. * 2) pattern for a query. * * @param fld field's name */ public Term(String fld) { this(fld, new BytesRef()); }
/** Constructs a Term with the given field and text. * <p>Note that a null field or null text value results in undefined * behavior for most Lucene APIs that accept a Term parameter. */ public Term(String fld, String text) { this(fld, new BytesRef(text)); }
@Override public BytesRef getUsing(@Nullable BytesRef using) { if (using == null) { using = new BytesRef(new byte[array.length]); } else if (using.bytes.length < array.length) { using.bytes = new byte[array.length]; } System.arraycopy(array, 0, using.bytes, 0, array.length); using.offset = 0; using.length = array.length; return using; }
/** * Factory that creates a new TermRangeQuery using Strings for term text. */ public static TermRangeQuery newStringRange(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) { BytesRef lower = lowerTerm == null ? null : new BytesRef(lowerTerm); BytesRef upper = upperTerm == null ? null : new BytesRef(upperTerm); return new TermRangeQuery(field, lower, upper, includeLower, includeUpper); }
/** * Creates a new BytesRef that points to a copy of the bytes from * <code>other</code> * <p> * The returned BytesRef will have a length of other.length * and an offset of zero. */ public static BytesRef deepCopyOf(BytesRef other) { return new BytesRef(ArrayUtil.copyOfSubArray(other.bytes, other.offset, other.offset + other.length), 0, other.length); }
/** * Build a new {@link BytesRef} that has the same content as this buffer. */ public BytesRef toBytesRef() { return new BytesRef(ArrayUtil.copyOfSubArray(ref.bytes, 0, ref.length)); }
/** * Expert: change the value of this field. See * {@link #setStringValue(String)}. */ public void setBytesValue(byte[] value) { setBytesValue(new BytesRef(value)); }
@Override protected String toString(byte[] value) { return new BytesRef(value).toString(); } };
private static BytesRef pack(int... point) { if (point == null) { throw new IllegalArgumentException("point must not be null"); } if (point.length == 0) { throw new IllegalArgumentException("point must not be 0 dimensions"); } byte[] packed = new byte[point.length * Integer.BYTES]; for (int dim = 0; dim < point.length; dim++) { encodeDimension(point[dim], packed, dim * Integer.BYTES); } return new BytesRef(packed); }
@SuppressWarnings("unused") static String brToString(byte[] b) { return brToString(new BytesRef(b)); }
/** Writes a string. * <p> * Writes strings as UTF-8 encoded bytes. First the length, in bytes, is * written as a {@link #writeVInt VInt}, followed by the bytes. * * @see DataInput#readString() */ public void writeString(String s) throws IOException { final BytesRef utf8Result = new BytesRef(s); writeVInt(utf8Result.length); writeBytes(utf8Result.bytes, utf8Result.offset, utf8Result.length); }
@Override public BytesRef read(DataInput in) throws IOException { final int len = in.readVInt(); if (len == 0) { return NO_OUTPUT; } else { final BytesRef output = new BytesRef(len); in.readBytes(output.bytes, 0, len); output.length = len; return output; } }
@Override public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException { reset(fieldInfo); // TODO: can we avoid new BR here? binaryValue = new BytesRef(value); write(); }
@Override public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException { reset(fieldInfo); // TODO: can we avoid new BR here? binaryValue = new BytesRef(value); write(); }
@Override public void intersect(IntersectVisitor visitor) throws IOException { final BytesRef scratch = new BytesRef(); final byte[] packedValue = new byte[packedBytesLength]; for(int i=0;i<numPoints;i++) { getValue(i, scratch); assert scratch.length == packedValue.length; System.arraycopy(scratch.bytes, scratch.offset, packedValue, 0, packedBytesLength); visitor.visit(getDocID(i), packedValue); } }
private static Terms getTerms( String value, int frequency ) throws IOException { TermsEnum termsEnum = mock( TermsEnum.class ); Terms terms = mock( Terms.class ); when( terms.iterator() ).thenReturn( termsEnum ); when( termsEnum.next() ).thenReturn( new BytesRef( value.getBytes() ) ).thenReturn( null ); when( termsEnum.docFreq() ).thenReturn( frequency ); return terms; }
private static BytesRef readBytesRef(IndexInput in) throws IOException { int numBytes = in.readVInt(); if (numBytes < 0) { throw new CorruptIndexException("invalid bytes length: " + numBytes, in); } BytesRef bytes = new BytesRef(); bytes.length = numBytes; bytes.bytes = new byte[numBytes]; in.readBytes(bytes.bytes, 0, numBytes); return bytes; }
TermsDict(TermsDictEntry entry, IndexInput data) throws IOException { this.entry = entry; RandomAccessInput addressesSlice = data.randomAccessSlice(entry.termsAddressesOffset, entry.termsAddressesLength); blockAddresses = DirectMonotonicReader.getInstance(entry.termsAddressesMeta, addressesSlice); bytes = data.slice("terms", entry.termsDataOffset, entry.termsDataLength); blockMask = (1L << entry.termsDictBlockShift) - 1; RandomAccessInput indexAddressesSlice = data.randomAccessSlice(entry.termsIndexAddressesOffset, entry.termsIndexAddressesLength); indexAddresses = DirectMonotonicReader.getInstance(entry.termsIndexAddressesMeta, indexAddressesSlice); indexBytes = data.slice("terms-index", entry.termsIndexOffset, entry.termsIndexLength); term = new BytesRef(entry.maxTermLength); }