Search in sources :

Example 1 with FilterClause

use of org.apache.lucene.search.FilterClause in project greplin-lucene-utils by Cue.

the class Filters method or.

/**
     * Returns a filter that allows documents that match any constituent
     * filter.  For convenience, null values are accepted and ignored.  If
     * all values are null, null will be returned.
     * @param filters the filters to combine
     * @return the combined filter
     */
@Nullable
public static Filter or(final Iterable<Filter> filters) {
    final BooleanFilter booleanFilter = new BooleanFilter();
    Filter lastFilter = null;
    int count = 0;
    for (Filter filter : filters) {
        if (filter != null) {
            booleanFilter.add(new FilterClause(filter, BooleanClause.Occur.SHOULD));
            count += 1;
            lastFilter = filter;
        }
    }
    if (count == 0) {
        return null;
    } else if (count == 1) {
        return lastFilter;
    } else {
        return booleanFilter;
    }
}
Also used : BooleanFilter(org.apache.lucene.search.BooleanFilter) Filter(org.apache.lucene.search.Filter) BooleanFilter(org.apache.lucene.search.BooleanFilter) FilterClause(org.apache.lucene.search.FilterClause) Nullable(javax.annotation.Nullable)

Example 2 with FilterClause

use of org.apache.lucene.search.FilterClause in project greplin-lucene-utils by Cue.

the class Filters method not.

/**
   * Returns a filter matching the inverse of the given filter.
   * @param filter the filter to return the opposite of
   * @return the negated filter
   */
public static Filter not(final Filter filter) {
    final BooleanFilter booleanFilter = new BooleanFilter();
    booleanFilter.add(new FilterClause(filter, BooleanClause.Occur.MUST_NOT));
    return booleanFilter;
}
Also used : BooleanFilter(org.apache.lucene.search.BooleanFilter) FilterClause(org.apache.lucene.search.FilterClause)

Example 3 with FilterClause

use of org.apache.lucene.search.FilterClause in project greplin-lucene-utils by Cue.

the class Filters method and.

/**
   * Returns a filter that allows documents that match every constituent
   * filter.  For convenience, null values are accepted and ignored.  If
   * all values are null, null will be returned.
   * @param filters the filters to combine
   * @return the combined filter
   */
@Nullable
public static Filter and(final Iterable<Filter> filters) {
    final BooleanFilter booleanFilter = new BooleanFilter();
    Filter lastFilter = null;
    int count = 0;
    for (Filter filter : filters) {
        if (filter != null) {
            booleanFilter.add(new FilterClause(filter, BooleanClause.Occur.MUST));
            count += 1;
            lastFilter = filter;
        }
    }
    if (count == 0) {
        return null;
    } else if (count == 1) {
        return lastFilter;
    } else {
        return booleanFilter;
    }
}
Also used : BooleanFilter(org.apache.lucene.search.BooleanFilter) Filter(org.apache.lucene.search.Filter) BooleanFilter(org.apache.lucene.search.BooleanFilter) FilterClause(org.apache.lucene.search.FilterClause) Nullable(javax.annotation.Nullable)

Aggregations

BooleanFilter (org.apache.lucene.search.BooleanFilter)3 FilterClause (org.apache.lucene.search.FilterClause)3 Nullable (javax.annotation.Nullable)2 Filter (org.apache.lucene.search.Filter)2