Search in sources :

Example 1 with OrdinalsFilter

use of org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude.OrdinalsFilter in project elasticsearch by elastic.

the class IncludeExcludeTests method testEmptyTermsWithOrds.

public void testEmptyTermsWithOrds() throws IOException {
    IncludeExclude inexcl = new IncludeExclude(new TreeSet<>(Collections.singleton(new BytesRef("foo"))), null);
    OrdinalsFilter filter = inexcl.convertToOrdinalsFilter(DocValueFormat.RAW);
    LongBitSet acceptedOrds = filter.acceptedGlobalOrdinals(DocValues.emptySortedSet());
    assertEquals(0, acceptedOrds.length());
    inexcl = new IncludeExclude(null, new TreeSet<>(Collections.singleton(new BytesRef("foo"))));
    filter = inexcl.convertToOrdinalsFilter(DocValueFormat.RAW);
    acceptedOrds = filter.acceptedGlobalOrdinals(DocValues.emptySortedSet());
    assertEquals(0, acceptedOrds.length());
}
Also used : TreeSet(java.util.TreeSet) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude) OrdinalsFilter(org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude.OrdinalsFilter) LongBitSet(org.apache.lucene.util.LongBitSet) BytesRef(org.apache.lucene.util.BytesRef)

Example 2 with OrdinalsFilter

use of org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude.OrdinalsFilter in project elasticsearch by elastic.

the class IncludeExcludeTests method testSingleTermWithOrds.

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

        boolean consumed = true;

        @Override
        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(DocValueFormat.RAW);
    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(DocValueFormat.RAW);
    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(DocValueFormat.RAW);
    acceptedOrds = filter.acceptedGlobalOrdinals(ords);
    assertEquals(1, acceptedOrds.length());
    assertFalse(acceptedOrds.get(0));
    inexcl = new IncludeExclude(// means everything included
    null, new TreeSet<>(Collections.singleton(new BytesRef("foo"))));
    filter = inexcl.convertToOrdinalsFilter(DocValueFormat.RAW);
    acceptedOrds = filter.acceptedGlobalOrdinals(ords);
    assertEquals(1, acceptedOrds.length());
    assertFalse(acceptedOrds.get(0));
}
Also used : RandomAccessOrds(org.apache.lucene.index.RandomAccessOrds) TreeSet(java.util.TreeSet) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude) OrdinalsFilter(org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude.OrdinalsFilter) LongBitSet(org.apache.lucene.util.LongBitSet) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

TreeSet (java.util.TreeSet)2 BytesRef (org.apache.lucene.util.BytesRef)2 LongBitSet (org.apache.lucene.util.LongBitSet)2 IncludeExclude (org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude)2 OrdinalsFilter (org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude.OrdinalsFilter)2 RandomAccessOrds (org.apache.lucene.index.RandomAccessOrds)1