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());
}
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));
}
Aggregations