Example usage for org.apache.lucene.util BytesRefHash size

List of usage examples for org.apache.lucene.util BytesRefHash size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of BytesRef values in this BytesRefHash .

Usage

From source file:de.unihildesheim.iw.lucene.util.BytesRefUtils.java

License:Open Source License

/**
 * Convert a {@link BytesRefHash} to a {@link BytesRefArray}.
 *
 * @param bh Hash//from   ww  w  .ja v  a 2  s . c om
 * @return Array
 */
public static BytesRefArray hashToArray(@NotNull final BytesRefHash bh) {
    final BytesRefArray ba = new BytesRefArray(Counter.newCounter(false));
    final BytesRef br = new BytesRef();
    for (int i = bh.size() - 1; i >= 0; i--) {
        ba.append(bh.get(i, br));
    }
    return ba;
}

From source file:de.unihildesheim.iw.lucene.util.BytesRefUtils.java

License:Open Source License

/**
 * Convert a {@link BytesRefHash} to a Set.
 *
 * @param bh Hash/*from  w w w.  j ava2  s. c o m*/
 * @return Set or {@code null}, if {@code bh} was null
 */
@Nullable
@Contract("null -> null; !null -> !null")
public static Set<String> hashToSet(@Nullable final BytesRefHash bh) {
    if (bh == null) {
        return null;
    }
    final Set<String> strSet = new HashSet<>(bh.size());
    final BytesRef br = new BytesRef();
    for (int i = bh.size() - 1; i >= 0; i--) {
        strSet.add(bh.get(i, br).utf8ToString());
    }
    return strSet;
}

From source file:org.elasticsearch.common.util.BytesRefHashTests.java

License:Apache License

private void assertAllIn(Set<String> strings, BytesRefHash hash) {
    BytesRef ref = new BytesRef();
    BytesRef scratch = new BytesRef();
    long count = hash.size();
    for (String string : strings) {
        ref.copyChars(string);//from w  w w .  j  ava  2  s  .co m
        long key = hash.add(ref); // add again to check duplicates
        assertEquals(string, hash.get((-key) - 1, scratch).utf8ToString());
        assertEquals(count, hash.size());
        assertTrue("key: " + key + " count: " + count + " string: " + string, key < count);
    }
}

From source file:solutions.siren.join.action.terms.collector.BytesRefTermsSet.java

License:Open Source License

@Override
protected void addAll(TermsSet terms) {
    if (!(terms instanceof BytesRefTermsSet)) {
        throw new UnsupportedOperationException("Invalid type: BytesRefTermsSet expected.");
    }//from w w  w . j  av  a  2s  .co m

    BytesRefHash input = ((BytesRefTermsSet) terms).set;
    BytesRef reusable = new BytesRef();
    for (int i = 0; i < input.size(); i++) {
        input.get(i, reusable);
        set.add(reusable);
    }
}