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

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

Introduction

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

Prototype

public BytesRef toBytesRef() 

Source Link

Document

Build a new BytesRef that has the same content as this buffer.

Usage

From source file:com.qwazr.search.index.BytesRefUtils.java

License:Apache License

final static public BytesRef from(final Integer value) {
    if (value == null)
        return new BytesRef(BytesRef.EMPTY_BYTES);
    final BytesRefBuilder builder = new BytesRefBuilder();
    NumericUtils.intToPrefixCoded(value, 0, builder);
    return builder.toBytesRef();
}

From source file:com.qwazr.search.index.BytesRefUtils.java

License:Apache License

final static public BytesRef from(final Long value) {
    if (value == null)
        return new BytesRef(BytesRef.EMPTY_BYTES);
    final BytesRefBuilder builder = new BytesRefBuilder();
    NumericUtils.longToPrefixCoded(value, 0, builder);
    return builder.toBytesRef();
}

From source file:com.qwazr.search.index.BytesRefUtils.java

License:Apache License

final static public BytesRef from(final Float value) {
    if (value == null)
        return new BytesRef(BytesRef.EMPTY_BYTES);
    final BytesRefBuilder builder = new BytesRefBuilder();
    NumericUtils.intToPrefixCoded(NumericUtils.floatToSortableInt(value), 0, builder);
    return builder.toBytesRef();
}

From source file:com.qwazr.search.index.BytesRefUtils.java

License:Apache License

final static public BytesRef from(final Double value) {
    if (value == null)
        return new BytesRef(BytesRef.EMPTY_BYTES);
    final BytesRefBuilder builder = new BytesRefBuilder();
    NumericUtils.longToPrefixCoded(NumericUtils.doubleToSortableLong(value), 0, builder);
    return builder.toBytesRef();
}

From source file:com.tcdi.zombodb.query.VisibilityQueryHelper.java

License:Apache License

private static boolean isCommitted(TermsEnum termsEnum, long xid, BytesRefBuilder builder) throws IOException {
    if (KNOWN_COMMITTED_XIDS.contains(xid))
        return true;

    if (termsEnum == null)
        return false;

    NumericUtils.longToPrefixCoded(xid, 0, builder);
    boolean isCommitted = termsEnum.seekExact(builder.toBytesRef());

    if (isCommitted)
        KNOWN_COMMITTED_XIDS.add(xid);//from   w w w.  j a v  a2  s.c om

    builder.clear();
    return isCommitted;
}

From source file:examples.fst.FstTest.java

public static void main(String[] args) throws IOException {
    // Input values (keys). These must be provided to Builder in Unicode sorted order!
    String inputValues[] = { "cat", "dog", "dogs" };
    long outputValues[] = { 5, 7, 12 };

    PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
    Builder<Long> builder = new Builder<Long>(INPUT_TYPE.BYTE1, outputs);
    BytesRefBuilder scratchBytes = new BytesRefBuilder();
    IntsRefBuilder scratchInts = new IntsRefBuilder();
    for (int i = 0; i < inputValues.length; i++) {
        scratchBytes.copyChars(inputValues[i]);
        builder.add(Util.toIntsRef(scratchBytes.toBytesRef(), scratchInts), outputValues[i]);
    }/* w  w w. ja v  a 2s  . c o  m*/
    FST<Long> fst = builder.finish();

    Long value = Util.get(fst, new BytesRef("dog"));
    System.out.println(value); // 7

    // Only works because outputs are also in sorted order
    IntsRef key = Util.getByOutput(fst, 12);
    System.out.println(Util.toBytesRef(key, scratchBytes).utf8ToString()); // dogs

}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@Override
public List<NodeMetaData> getCascadeNodes(List<Long> txnIds)
        throws AuthenticationException, IOException, JSONException {
    List<FieldInstance> list = AlfrescoSolrDataModel.getInstance()
            .getIndexedFieldNamesForProperty(ContentModel.PROP_CASCADE_TX).getFields();
    FieldInstance fieldInstance = list.get(0);

    RefCounted<SolrIndexSearcher> refCounted = null;
    IntArrayList docList;//from  ww  w  . j a va2  s  . c  o m
    Set<Long> parentNodesId = new HashSet<>();

    try {
        refCounted = core.getSearcher();
        SolrIndexSearcher searcher = refCounted.get();
        String field = fieldInstance.getField();
        SchemaField schemaField = searcher.getSchema().getField(field);
        FieldType fieldType = schemaField.getType();
        BooleanQuery.Builder builder = new BooleanQuery.Builder();
        BooleanQuery booleanQuery;

        for (Long l : txnIds) {
            BytesRefBuilder bytesRefBuilder = new BytesRefBuilder();
            fieldType.readableToIndexed(l.toString(), bytesRefBuilder);
            TermQuery termQuery = new TermQuery(new Term(field, bytesRefBuilder.toBytesRef()));
            BooleanClause booleanClause = new BooleanClause(termQuery, BooleanClause.Occur.SHOULD);
            builder.add(booleanClause);
        }

        booleanQuery = builder.build();

        DocListCollector collector = new DocListCollector();
        searcher.search(booleanQuery, collector);
        docList = collector.getDocs();
        int size = docList.size();
        for (int i = 0; i < size; i++) {
            int docId = docList.get(i);
            Document document = searcher.doc(docId, REQUEST_ONLY_ID_FIELD);
            IndexableField indexableField = document.getField(FIELD_SOLR4_ID);
            String id = indexableField.stringValue();
            TenantAclIdDbId ids = AlfrescoSolrDataModel.decodeNodeDocumentId(id);
            parentNodesId.add(ids.dbId);
        }
    } finally {
        ofNullable(refCounted).ifPresent(RefCounted::decref);
    }

    List<NodeMetaData> allNodeMetaDatas = new ArrayList<>();

    for (Long parentNodeId : parentNodesId) {
        NodeMetaDataParameters nmdp = new NodeMetaDataParameters();
        nmdp.setFromNodeId(parentNodeId);
        nmdp.setToNodeId(parentNodeId);
        nmdp.setIncludeAclId(false);
        nmdp.setIncludeChildAssociations(false);
        nmdp.setIncludeChildIds(true);
        nmdp.setIncludeOwner(false);
        nmdp.setIncludeParentAssociations(false);
        nmdp.setIncludePaths(true);
        nmdp.setIncludeProperties(false);
        nmdp.setIncludeTxnId(true);
        // Gets only one
        List<NodeMetaData> nodeMetaDatas = repositoryClient.getNodesMetaData(nmdp, 1);
        allNodeMetaDatas.addAll(nodeMetaDatas);
    }

    return allNodeMetaDatas;
}

From source file:org.apache.solr.search.GraphTermsQParserPlugin.java

License:Apache License

@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
    return new QParser(qstr, localParams, params, req) {
        @Override//from   w w w .  jav  a 2 s.co  m
        public Query parse() throws SyntaxError {
            String fname = localParams.get(QueryParsing.F);
            FieldType ft = req.getSchema().getFieldTypeNoEx(fname);
            int maxDocFreq = localParams.getInt("maxDocFreq", Integer.MAX_VALUE);
            String qstr = localParams.get(QueryParsing.V);//never null

            if (qstr.length() == 0) {
                return new MatchNoDocsQuery();
            }

            final String[] splitVals = qstr.split(",");

            Term[] terms = new Term[splitVals.length];
            BytesRefBuilder term = new BytesRefBuilder();
            for (int i = 0; i < splitVals.length; i++) {
                String stringVal = splitVals[i].trim();
                if (ft != null) {
                    ft.readableToIndexed(stringVal, term);
                } else {
                    term.copyChars(stringVal);
                }
                BytesRef ref = term.toBytesRef();
                terms[i] = new Term(fname, ref);
            }

            ArrayUtil.timSort(terms);
            return new ConstantScoreQuery(new GraphTermsQuery(fname, terms, maxDocFreq));
        }
    };
}

From source file:org.apache.solr.search.mlt.SimpleMLTQParser.java

License:Apache License

private Term createNumericTerm(String field, String uniqueValue) {
    BytesRefBuilder bytesRefBuilder = new BytesRefBuilder();
    bytesRefBuilder.grow(NumericUtils.BUF_SIZE_INT);
    NumericUtils.intToPrefixCoded(Integer.parseInt(uniqueValue), 0, bytesRefBuilder);
    return new Term(field, bytesRefBuilder.toBytesRef());
}

From source file:org.codelibs.elasticsearch.common.bytes.CompositeBytesReference.java

License:Apache License

@Override
public BytesRef toBytesRef() {
    BytesRefBuilder builder = new BytesRefBuilder();
    builder.grow(length());/*from   w  w  w.  ja va  2s .c o  m*/
    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();
}