Example usage for org.apache.lucene.util BytesRef BytesRef

List of usage examples for org.apache.lucene.util BytesRef BytesRef

Introduction

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

Prototype

public BytesRef(CharSequence text) 

Source Link

Document

Initialize the byte[] from the UTF8 bytes for the provided String.

Usage

From source file:io.crate.expression.reference.doc.blob.BlobDigestExpression.java

License:Apache License

@Override
public BytesRef value() {
    return new BytesRef(row.getName());
}

From source file:io.crate.expression.reference.doc.BytesRefColumnReferenceTest.java

License:Apache License

@Override
protected void insertValues(IndexWriter writer) throws Exception {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < 10; i++) {
        builder.append(i);/*from ww  w .  j a va  2 s  .c  om*/
        Document doc = new Document();
        doc.add(new StringField("_id", Integer.toString(i), Field.Store.NO));
        doc.add(new SortedDocValuesField(column, new BytesRef(builder.toString())));
        writer.addDocument(doc);
    }
}

From source file:io.crate.expression.reference.doc.IpColumnReferenceTest.java

License:Apache License

private static void addIPv6Values(IndexWriter writer) throws IOException {
    for (int i = 10; i < 20; i++) {
        Document doc = new Document();
        doc.add(new StringField("_id", Integer.toString(i), Field.Store.NO));
        InetAddress address = InetAddresses
                .forString("7bd0:8082:2df8:487e:e0df:e7b5:9362:" + Integer.toHexString(i));
        doc.add(new SortedSetDocValuesField(IP_COLUMN, new BytesRef(InetAddressPoint.encode(address))));
        writer.addDocument(doc);//from w w w . j a v a  2s  . co  m
    }
}

From source file:io.crate.expression.reference.doc.IpColumnReferenceTest.java

License:Apache License

private static void addIPv4Values(IndexWriter writer) throws IOException {
    for (int i = 0; i < 10; i++) {
        Document doc = new Document();
        doc.add(new StringField("_id", Integer.toString(i), Field.Store.NO));
        InetAddress address = InetAddresses.forString("192.168.0." + i);
        doc.add(new SortedSetDocValuesField(IP_COLUMN, new BytesRef(InetAddressPoint.encode(address))));
        if (i == 0) {
            address = InetAddresses.forString("192.168.0.1");
            doc.add(new SortedSetDocValuesField(IP_ARRAY_COLUMN,
                    new BytesRef(InetAddressPoint.encode(address))));
            address = InetAddresses.forString("192.168.0.2");
            doc.add(new SortedSetDocValuesField(IP_ARRAY_COLUMN,
                    new BytesRef(InetAddressPoint.encode(address))));
        }/*  w w  w. j a  va 2  s .c o  m*/
        writer.addDocument(doc);
    }
}

From source file:io.crate.expression.reference.doc.IpColumnReferenceTest.java

License:Apache License

@Test
public void testIpExpression() throws Exception {
    IpColumnReference columnReference = new IpColumnReference(IP_COLUMN);
    columnReference.startCollect(ctx);/*from w w w. j a v  a  2s . c o  m*/
    columnReference.setNextReader(readerContext);
    IndexSearcher searcher = new IndexSearcher(readerContext.reader());
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 21);
    assertThat(topDocs.scoreDocs.length, is(21));

    int i = 0;
    for (ScoreDoc doc : topDocs.scoreDocs) {
        columnReference.setNextDocId(doc.doc);
        if (i == 20) {
            assertThat(columnReference.value(), is(nullValue()));
        } else if (i < 10) {
            assertThat(columnReference.value(), is(new BytesRef("192.168.0." + i)));
        } else {
            assertThat(columnReference.value(),
                    is(new BytesRef("7bd0:8082:2df8:487e:e0df:e7b5:9362:" + Integer.toHexString(i))));
        }
        i++;
    }
}

From source file:io.crate.expression.reference.doc.lucene.IdFromUidCollectorExpression.java

License:Apache License

@Override
public BytesRef value() {
    return new BytesRef(visitor.uid().id());
}

From source file:io.crate.expression.reference.file.LineContext.java

License:Apache License

@Nullable
public BytesRef sourceAsBytesRef() {
    if (rawSource != null) {
        return new BytesRef(rawSource);
    }
    return null;
}

From source file:io.crate.expression.reference.file.LineContext.java

License:Apache License

public Object get(ColumnIdent columnIdent) {
    Map<String, Object> parentMap = sourceAsMap();
    if (parentMap == null) {
        return null;
    }/*from w  w  w  .  j a  v a  2  s .co  m*/
    Object val = ColumnIdent.get(parentMap, columnIdent);
    if (val instanceof String) {
        return new BytesRef((String) val);
    }
    return val;
}

From source file:io.crate.expression.reference.sys.check.AbstractSysCheck.java

License:Apache License

protected AbstractSysCheck(int id, String description, Severity severity, String linkPattern) {
    String linkedDescriptionBuilder = description + " " + linkPattern + id;
    this.description = new BytesRef(linkedDescriptionBuilder);

    this.id = id;
    this.severity = severity;
}

From source file:io.crate.expression.reference.sys.check.cluster.LicenseEnterpriseChecks.java

License:Apache License

@Override
public BytesRef description() {
    return new BytesRef(DESCRIPTION);
}