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

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

Introduction

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

Prototype

public int find(BytesRef bytes) 

Source Link

Document

Returns the id of the given BytesRef .

Usage

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

License:Open Source License

@SuppressWarnings("ImplicitNumericConversion")
@Test//from  ww  w . jav  a  2s .  com
public void testHashToArray() throws Exception {
    final Collection<String> data = new HashSet<>(3);
    data.add("foo");
    data.add("bar");
    data.add("baz");

    final BytesRefHash brh = new BytesRefHash();
    data.stream().map(BytesRef::new).forEach(brh::add);

    final BytesRefArray bra = BytesRefUtils.hashToArray(brh);

    Assert.assertEquals("Not all terms found.", data.size(), bra.size());

    final BytesRefIterator bri = bra.iterator();
    BytesRef br;
    while ((br = bri.next()) != null) {
        Assert.assertNotSame("BytesRef not found.", -1, brh.find(br));
    }
}