Example usage for org.apache.lucene.util LongBitSet get

List of usage examples for org.apache.lucene.util LongBitSet get

Introduction

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

Prototype

public boolean get(long index) 

Source Link

Usage

From source file:org.elasticsearch.search.aggregations.support.IncludeExcludeTests.java

License:Apache License

public void testSingleTermWithOrds() throws IOException {
    RandomAccessOrds ords = new RandomAccessOrds() {

        boolean consumed = true;

        @Override/*from   w  ww. jav a2s.co m*/
        public void setDocument(int docID) {
            consumed = false;
        }

        @Override
        public long nextOrd() {
            if (consumed) {
                return SortedSetDocValues.NO_MORE_ORDS;
            } else {
                consumed = true;
                return 0;
            }
        }

        @Override
        public BytesRef lookupOrd(long ord) {
            assertEquals(0, ord);
            return new BytesRef("foo");
        }

        @Override
        public long getValueCount() {
            return 1;
        }

        @Override
        public long ordAt(int index) {
            return 0;
        }

        @Override
        public int cardinality() {
            return 1;
        }
    };
    IncludeExclude inexcl = new IncludeExclude(new TreeSet<>(Collections.singleton(new BytesRef("foo"))), null);
    OrdinalsFilter filter = inexcl.convertToOrdinalsFilter();
    LongBitSet acceptedOrds = filter.acceptedGlobalOrdinals(ords);
    assertEquals(1, acceptedOrds.length());
    assertTrue(acceptedOrds.get(0));

    inexcl = new IncludeExclude(new TreeSet<>(Collections.singleton(new BytesRef("bar"))), null);
    filter = inexcl.convertToOrdinalsFilter();
    acceptedOrds = filter.acceptedGlobalOrdinals(ords);
    assertEquals(1, acceptedOrds.length());
    assertFalse(acceptedOrds.get(0));

    inexcl = new IncludeExclude(new TreeSet<>(Collections.singleton(new BytesRef("foo"))),
            new TreeSet<>(Collections.singleton(new BytesRef("foo"))));
    filter = inexcl.convertToOrdinalsFilter();
    acceptedOrds = filter.acceptedGlobalOrdinals(ords);
    assertEquals(1, acceptedOrds.length());
    assertFalse(acceptedOrds.get(0));

    inexcl = new IncludeExclude(null, // means everything included
            new TreeSet<>(Collections.singleton(new BytesRef("foo"))));
    filter = inexcl.convertToOrdinalsFilter();
    acceptedOrds = filter.acceptedGlobalOrdinals(ords);
    assertEquals(1, acceptedOrds.length());
    assertFalse(acceptedOrds.get(0));
}