Java Code Examples for org.elasticsearch.common.lucene.BytesRefs#toBytesRef()

The following examples show how to use org.elasticsearch.common.lucene.BytesRefs#toBytesRef() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LowerFunction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public BytesRef evaluate(Input<Object>... args) {
    Object stringValue = args[0].value();
    if (stringValue == null) {
        return null;
    }

    BytesRef inputByteRef = BytesRefs.toBytesRef(stringValue);

    char[] ref = new char[inputByteRef.length];
    int len = UnicodeUtil.UTF8toUTF16(inputByteRef.bytes, inputByteRef.offset, inputByteRef.length, ref);
    charUtils.toLowerCase(ref, 0, len);

    byte[] res = new byte[UnicodeUtil.MAX_UTF8_BYTES_PER_CHAR * len];
    len = UnicodeUtil.UTF16toUTF8(ref, 0, len, res);
    return new BytesRef(res, 0, len);
}
 
Example 2
Source File: UpperFunction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public BytesRef evaluate(Input<Object>... args) {
    Object stringValue = args[0].value();
    if (stringValue == null) {
        return null;
    }

    BytesRef inputByteRef = BytesRefs.toBytesRef(stringValue);

    char[] ref = new char[inputByteRef.length];
    int len = UnicodeUtil.UTF8toUTF16(inputByteRef.bytes, inputByteRef.offset, inputByteRef.length, ref);
    charUtils.toUpperCase(ref, 0, len);

    byte[] res = new byte[UnicodeUtil.MAX_UTF8_BYTES_PER_CHAR * len];
    len = UnicodeUtil.UTF16toUTF8(ref, 0, len, res);
    return new BytesRef(res, 0, len);
}
 
Example 3
Source File: LuceneQueryBuilder.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Query apply(Function input, Context context) throws IOException {
    Tuple<Reference, Literal> prepare = prepare(input);
    if (prepare == null) { return null; }
    String fieldName = prepare.v1().info().ident().columnIdent().fqn();
    Object value = prepare.v2().value();

    if (value instanceof BytesRef) {
        RegexQuery query = new RegexQuery(new Term(fieldName, BytesRefs.toBytesRef(value)));
        query.setRegexImplementation(new JavaUtilRegexCapabilities(
                JavaUtilRegexCapabilities.FLAG_CASE_INSENSITIVE |
                JavaUtilRegexCapabilities.FLAG_UNICODE_CASE));
        return query;
    }
    throw new IllegalArgumentException("Can only use ~* with patterns of type string");
}
 
Example 4
Source File: ExtendedFsStats.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public Info(String path,
            @Nullable String dev,
            long total,
            long free,
            long available,
            long used,
            long diskReads,
            long diskWrites,
            long diskReadBytes,
            long diskWriteBytes) {
    this.path = new BytesRef(path);
    this.dev = BytesRefs.toBytesRef(dev);
    this.total = total;
    this.free = free;
    this.available = available;
    this.used = used;
    this.diskReads = diskReads;
    this.diskWrites = diskWrites;
    this.diskReadBytes = diskReadBytes;
    this.diskWriteBytes = diskWriteBytes;
}
 
Example 5
Source File: Inputs.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public BytesRef apply(@Nullable Input<?> input) {
    if (input == null) {
        return null;
    }
    return BytesRefs.toBytesRef(input.value());
}
 
Example 6
Source File: ClientMessages.java    From crate with Apache License 2.0 5 votes vote down vote up
static void sendBindMessage(ByteBuf buffer,
                            String portalName,
                            String statementName,
                            List<Object> params) {
    buffer.writeByte('B');
    byte[] portalBytes = portalName.getBytes(StandardCharsets.UTF_8);
    byte[] statementBytes = statementName.getBytes(StandardCharsets.UTF_8);

    int beforeLengthWriterIndex = buffer.writerIndex();
    buffer.writeInt(0);
    writeCString(buffer, portalBytes);
    writeCString(buffer, statementBytes);
    buffer.writeShort(0); // formatCode use 0 to default to text for all
    buffer.writeShort(params.size());

    int paramsLength = 0;
    for (Object param : params) {
        BytesRef value = BytesRefs.toBytesRef(param);
        buffer.writeInt(value.length);
        // the strings here are _not_ zero-padded because we specify the length upfront
        buffer.writeBytes(value.bytes, value.offset, value.length);
        paramsLength += 4 + value.length;
    }
    buffer.writeShort(0); // numResultFormatCodes - 0 to default to text for all

    buffer.setInt(beforeLengthWriterIndex,
        4 +
        portalBytes.length + 1 +
        statementBytes.length + 1 +
        2 + // numFormatCodes
        2 + // numParams
        paramsLength +
        2); // numResultColumnFormatCodes
}
 
Example 7
Source File: TablesSettingsExpression.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public BytesRef value() {
    return BytesRefs.toBytesRef(row.tableParameters().get(paramName));
}
 
Example 8
Source File: BlobShardTableNameExpression.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Inject
public BlobShardTableNameExpression(ShardId shardId) {
    this.tableName = BytesRefs.toBytesRef(BlobIndices.STRIP_PREFIX.apply(shardId.index().name()));
}
 
Example 9
Source File: PartitionsSettingsExpression.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public BytesRef value() {
    return BytesRefs.toBytesRef(row.tableParameters().get(paramName));
}
 
Example 10
Source File: QueryBuilderHelper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public Query rangeQuery(String columnName, Object from, Object to, boolean includeLower, boolean includeUpper) {
    return new TermRangeQuery(columnName, BytesRefs.toBytesRef(from), BytesRefs.toBytesRef(to), includeLower, includeUpper);
}
 
Example 11
Source File: MappedFieldType.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/** Returns the indexed value used to construct search "values". */
public BytesRef indexedValueForSearch(Object value) {
    return BytesRefs.toBytesRef(value);
}
 
Example 12
Source File: TermBasedFieldType.java    From crate with Apache License 2.0 4 votes vote down vote up
/** Returns the indexed value used to construct search "values".
 *  This method is used for the default implementations of most
 *  query factory methods such as {@link #termQuery}. */
protected BytesRef indexedValueForSearch(Object value) {
    return BytesRefs.toBytesRef(value);
}
 
Example 13
Source File: ReferenceMapper.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Returns the indexed value used to construct search "values".
 * This method is used for the default implementations of most
 * query factory methods such as {@link #termQuery}.
 *
 * @param value the value
 * @return indexed value
 */
BytesRef indexedValueForSearch(Object value) {
    return BytesRefs.toBytesRef(value);
}