Search in sources :

Example 1 with NotFilterBuilder

use of org.elasticsearch.index.query.NotFilterBuilder in project bw-calendar-engine by Bedework.

the class TermOrTerms method makeFb.

FilterBuilder makeFb() {
    final FilterBuilder fb;
    if (!isTerms) {
        final TermFilterBuilder tfb = FilterBuilders.termFilter(fldName, value);
        if (filterName != null) {
            tfb.filterName(filterName);
        }
        fb = tfb;
    } else {
        final List vals = (List) value;
        FilterBuilder newFb = null;
        if (anding) {
            for (final Object o : vals) {
                if (o instanceof MatchNone) {
                    // and false is always false
                    newFb = (FilterBuilder) o;
                    break;
                }
            }
        } else {
            for (final Object o : vals) {
                if (o instanceof MatchAllFilterBuilder) {
                    // or true is always true
                    newFb = (FilterBuilder) o;
                    break;
                }
            }
        }
        if (newFb != null) {
            fb = newFb;
        } else {
            final TermsFilterBuilder tfb = FilterBuilders.termsFilter(fldName, (Iterable<?>) value).execution(exec);
            if (filterName != null) {
                tfb.filterName(filterName);
            }
            fb = tfb;
        }
    }
    if (!not) {
        return fb;
    }
    if (fb instanceof MatchAllFilterBuilder) {
        return new MatchNone();
    }
    if (fb instanceof MatchNone) {
        return new MatchAllFilterBuilder();
    }
    return new NotFilterBuilder(fb);
}
Also used : MatchAllFilterBuilder(org.elasticsearch.index.query.MatchAllFilterBuilder) TermFilterBuilder(org.elasticsearch.index.query.TermFilterBuilder) TermFilterBuilder(org.elasticsearch.index.query.TermFilterBuilder) FilterBuilder(org.elasticsearch.index.query.FilterBuilder) NotFilterBuilder(org.elasticsearch.index.query.NotFilterBuilder) BaseFilterBuilder(org.elasticsearch.index.query.BaseFilterBuilder) MatchAllFilterBuilder(org.elasticsearch.index.query.MatchAllFilterBuilder) TermsFilterBuilder(org.elasticsearch.index.query.TermsFilterBuilder) TermsFilterBuilder(org.elasticsearch.index.query.TermsFilterBuilder) NotFilterBuilder(org.elasticsearch.index.query.NotFilterBuilder) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 BaseFilterBuilder (org.elasticsearch.index.query.BaseFilterBuilder)1 FilterBuilder (org.elasticsearch.index.query.FilterBuilder)1 MatchAllFilterBuilder (org.elasticsearch.index.query.MatchAllFilterBuilder)1 NotFilterBuilder (org.elasticsearch.index.query.NotFilterBuilder)1 TermFilterBuilder (org.elasticsearch.index.query.TermFilterBuilder)1 TermsFilterBuilder (org.elasticsearch.index.query.TermsFilterBuilder)1