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

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

Introduction

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

Prototype

public long length() 

Source Link

Document

Returns the number of bits stored in this bitset.

Usage

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

License:Apache License

public void testEmptyTermsWithOrds() throws IOException {
    IncludeExclude inexcl = new IncludeExclude(new TreeSet<>(Collections.singleton(new BytesRef("foo"))), null);
    OrdinalsFilter filter = inexcl.convertToOrdinalsFilter();
    LongBitSet acceptedOrds = filter.acceptedGlobalOrdinals(DocValues.emptySortedSet());
    assertEquals(0, acceptedOrds.length());

    inexcl = new IncludeExclude(null, new TreeSet<>(Collections.singleton(new BytesRef("foo"))));
    filter = inexcl.convertToOrdinalsFilter();
    acceptedOrds = filter.acceptedGlobalOrdinals(DocValues.emptySortedSet());
    assertEquals(0, acceptedOrds.length());
}

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  .j  a  v  a2 s. com
        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));
}