Example usage for org.apache.lucene.util BytesRefBuilder grow

List of usage examples for org.apache.lucene.util BytesRefBuilder grow

Introduction

In this page you can find the example usage for org.apache.lucene.util BytesRefBuilder grow.

Prototype

public void grow(int capacity) 

Source Link

Document

Ensure that this builder can hold at least capacity bytes without resizing.

Usage

From source file:elhuyar.bilakit.Dictionary.java

License:Apache License

static void encodeFlags(BytesRefBuilder b, char flags[]) {
      int len = flags.length << 1;
      b.grow(len);
      b.clear();/*from  www. jav a  2  s  . c om*/
      for (int i = 0; i < flags.length; i++) {
          int flag = flags[i];
          b.append((byte) ((flag >> 8) & 0xff));
          b.append((byte) (flag & 0xff));
      }
  }

From source file:org.apache.solr.codecs.onsql.ONSQLUtil.java

License:Apache License

public static void readLine(DataInput in, BytesRefBuilder scratch) throws IOException {
    int upto = 0;
    while (true) {
        byte b = in.readByte();
        scratch.grow(1 + upto);
        if (b == ESCAPE) {
            scratch.setByteAt(upto++, in.readByte());
        } else {/*  w  ww.jav  a 2  s.  co m*/
            if (b == NEWLINE) {
                break;
            } else {
                scratch.setByteAt(upto++, b);
            }
        }
    }
    scratch.setLength(upto);
}

From source file:org.apache.solr.legacy.LegacyNumericUtils.java

License:Apache License

/**
 * Returns prefix coded bits after reducing the precision by <code>shift</code> bits.
 * This is method is used by {@link org.apache.solr.legacy.LegacyNumericTokenStream}.
 * After encoding, {@code bytes.offset} will always be 0. 
 * @param val the numeric value/*from   w  w w . j  a va2 s  .c o m*/
 * @param shift how many bits to strip from the right
 * @param bytes will contain the encoded value
 */
public static void longToPrefixCoded(final long val, final int shift, final BytesRefBuilder bytes) {
    // ensure shift is 0..63
    if ((shift & ~0x3f) != 0) {
        throw new IllegalArgumentException("Illegal shift value, must be 0..63; got shift=" + shift);
    }
    int nChars = (((63 - shift) * 37) >> 8) + 1; // i/7 is the same as (i*37)>>8 for i in 0..63
    bytes.setLength(nChars + 1); // one extra for the byte that contains the shift info
    bytes.grow(BUF_SIZE_LONG);
    bytes.setByteAt(0, (byte) (SHIFT_START_LONG + shift));
    long sortableBits = val ^ 0x8000000000000000L;
    sortableBits >>>= shift;
    while (nChars > 0) {
        // Store 7 bits per byte for compatibility
        // with UTF-8 encoding of terms
        bytes.setByteAt(nChars--, (byte) (sortableBits & 0x7f));
        sortableBits >>>= 7;
    }
}

From source file:org.apache.solr.legacy.LegacyNumericUtils.java

License:Apache License

/**
 * Returns prefix coded bits after reducing the precision by <code>shift</code> bits.
 * This is method is used by {@link org.apache.solr.legacy.LegacyNumericTokenStream}.
 * After encoding, {@code bytes.offset} will always be 0.
 * @param val the numeric value//from w  ww . ja v a 2s . c  o  m
 * @param shift how many bits to strip from the right
 * @param bytes will contain the encoded value
 */
public static void intToPrefixCoded(final int val, final int shift, final BytesRefBuilder bytes) {
    // ensure shift is 0..31
    if ((shift & ~0x1f) != 0) {
        throw new IllegalArgumentException("Illegal shift value, must be 0..31; got shift=" + shift);
    }
    int nChars = (((31 - shift) * 37) >> 8) + 1; // i/7 is the same as (i*37)>>8 for i in 0..63
    bytes.setLength(nChars + 1); // one extra for the byte that contains the shift info
    bytes.grow(LegacyNumericUtils.BUF_SIZE_LONG); // use the max
    bytes.setByteAt(0, (byte) (SHIFT_START_INT + shift));
    int sortableBits = val ^ 0x80000000;
    sortableBits >>>= shift;
    while (nChars > 0) {
        // Store 7 bits per byte for compatibility
        // with UTF-8 encoding of terms
        bytes.setByteAt(nChars--, (byte) (sortableBits & 0x7f));
        sortableBits >>>= 7;
    }
}

From source file:org.apache.solr.schema.DatePointField.java

License:Apache License

@Override
public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
    Date date = (Date) toNativeType(val.toString());
    result.grow(Long.BYTES);
    result.setLength(Long.BYTES);
    LongPoint.encodeDimension(date.getTime(), result.bytes(), 0);
}

From source file:org.apache.solr.schema.DoublePointField.java

License:Apache License

@Override
public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
    result.grow(Double.BYTES);
    result.setLength(Double.BYTES);
    DoublePoint.encodeDimension(Double.parseDouble(val.toString()), result.bytes(), 0);
}

From source file:org.apache.solr.schema.EnumFieldType.java

License:Apache License

@Override
public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
    final String s = val.toString();
    if (s == null)
        return;/*  ww w .j ava 2 s.c o  m*/

    result.grow(Integer.BYTES);
    result.setLength(Integer.BYTES);
    final Integer intValue = enumMapping.stringValueToIntValue(s);
    NumericUtils.intToSortableBytes(intValue, result.bytes(), 0);
}

From source file:org.apache.solr.schema.EnumFieldType.java

License:Apache License

@Override
public String storedToIndexed(IndexableField f) {
    final Number val = f.numericValue();
    if (val == null)
        return null;
    final BytesRefBuilder bytes = new BytesRefBuilder();
    bytes.grow(Integer.BYTES);
    bytes.setLength(Integer.BYTES);
    NumericUtils.intToSortableBytes(val.intValue(), bytes.bytes(), 0);
    return bytes.get().utf8ToString();
}

From source file:org.apache.solr.schema.FloatPointField.java

License:Apache License

@Override
public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
    result.grow(Float.BYTES);
    result.setLength(Float.BYTES);
    FloatPoint.encodeDimension(Float.parseFloat(val.toString()), result.bytes(), 0);
}

From source file:org.apache.solr.schema.IntPointField.java

License:Apache License

@Override
public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
    result.grow(Integer.BYTES);
    result.setLength(Integer.BYTES);
    IntPoint.encodeDimension(Integer.parseInt(val.toString()), result.bytes(), 0);
}