org.apache.lucene.queries.BooleanFilter Java Examples

The following examples show how to use org.apache.lucene.queries.BooleanFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BooleanFilterConstructor.java    From linden with Apache License 2.0 6 votes vote down vote up
@Override
protected Filter construct(LindenFilter lindenFilter, LindenConfig config) throws Exception {
  List<LindenBooleanSubFilter> booleanSubFilterList = lindenFilter.getBooleanFilter().getFilters();
  BooleanFilter booleanFilter = new BooleanFilter();
  for (LindenBooleanSubFilter booleanSubFilter : booleanSubFilterList) {
    LindenFilter subFilter = booleanSubFilter.getFilter();
    switch (booleanSubFilter.clause) {
      case MUST:
        booleanFilter.add(FilterConstructor.constructFilter(subFilter, config), BooleanClause.Occur.MUST);
        continue;
      case SHOULD:
        booleanFilter.add(FilterConstructor.constructFilter(subFilter, config), BooleanClause.Occur.SHOULD);
        continue;
      case MUST_NOT:
        booleanFilter.add(FilterConstructor.constructFilter(subFilter, config), BooleanClause.Occur.MUST_NOT);
    }
  }
  return booleanFilter;
}
 
Example #2
Source File: AliasBlurFilterCache.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
private Filter buildNewFilter(Query query, ConcurrentMap<String, String> filterAlias, FilterParser filterParser)
    throws ParseException {
  if (query instanceof BooleanQuery) {
    BooleanQuery booleanQuery = (BooleanQuery) query;
    BooleanFilter booleanFilter = new BooleanFilter();
    for (BooleanClause clause : booleanQuery.clauses()) {
      booleanFilter.add(buildNewFilter(clause.getQuery(), filterAlias, filterParser), clause.getOccur());
    }
    return booleanFilter;
  } else if (query instanceof TermQuery) {
    TermQuery termQuery = (TermQuery) query;
    Term term = termQuery.getTerm();
    String key = term.toString();
    String queryStr = filterAlias.get(key);
    if (queryStr == null) {
      return new QueryWrapperFilter(termQuery);
    }
    String id = getId(key);
    return new FilterCache(id, new QueryWrapperFilter(filterParser.parse(queryStr)));
  } else {
    return new QueryWrapperFilter(query);
  }
}
 
Example #3
Source File: NotNullFieldFilterConstructor.java    From linden with Apache License 2.0 5 votes vote down vote up
@Override
protected Filter construct(LindenFilter lindenFilter, LindenConfig config) throws Exception {
  LindenNotNullFieldFilter lindenNotNullFieldFilter = lindenFilter.getNotNullFieldFilter();

  NotNullFieldFilter notNullFieldFilter = new NotNullFieldFilter(lindenNotNullFieldFilter.getField());
  if (!lindenNotNullFieldFilter.isReverse()) {
    return notNullFieldFilter;
  }

  BooleanFilter booleanFilter = new BooleanFilter();
  booleanFilter.add(notNullFieldFilter, BooleanClause.Occur.MUST_NOT);
  return booleanFilter;
}
 
Example #4
Source File: LuceneIndex.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private static final Filter numericFilter(String key, Cmp relation, Number value) {
    switch (relation) {
        case EQUAL:
            return AttributeUtil.isWholeNumber(value) ?
                    NumericRangeFilter.newLongRange(key, value.longValue(), value.longValue(), true, true) :
                    NumericRangeFilter.newDoubleRange(key, value.doubleValue(), value.doubleValue(), true, true);
        case NOT_EQUAL:
            BooleanFilter q = new BooleanFilter();
            if (AttributeUtil.isWholeNumber(value)) {
                q.add(NumericRangeFilter.newLongRange(key, Long.MIN_VALUE, value.longValue(), true, false), BooleanClause.Occur.SHOULD);
                q.add(NumericRangeFilter.newLongRange(key, value.longValue(), Long.MAX_VALUE, false, true), BooleanClause.Occur.SHOULD);
            } else {
                q.add(NumericRangeFilter.newDoubleRange(key, Double.MIN_VALUE, value.doubleValue(), true, false), BooleanClause.Occur.SHOULD);
                q.add(NumericRangeFilter.newDoubleRange(key, value.doubleValue(), Double.MAX_VALUE, false, true), BooleanClause.Occur.SHOULD);
            }
            return q;
        case LESS_THAN:
            return (AttributeUtil.isWholeNumber(value)) ?
                    NumericRangeFilter.newLongRange(key, Long.MIN_VALUE, value.longValue(), true, false) :
                    NumericRangeFilter.newDoubleRange(key, Double.MIN_VALUE, value.doubleValue(), true, false);
        case LESS_THAN_EQUAL:
            return (AttributeUtil.isWholeNumber(value)) ?
                    NumericRangeFilter.newLongRange(key, Long.MIN_VALUE, value.longValue(), true, true) :
                    NumericRangeFilter.newDoubleRange(key, Double.MIN_VALUE, value.doubleValue(), true, true);
        case GREATER_THAN:
            return (AttributeUtil.isWholeNumber(value)) ?
                    NumericRangeFilter.newLongRange(key, value.longValue(), Long.MAX_VALUE, false, true) :
                    NumericRangeFilter.newDoubleRange(key, value.doubleValue(), Double.MAX_VALUE, false, true);
        case GREATER_THAN_EQUAL:
            return (AttributeUtil.isWholeNumber(value)) ?
                    NumericRangeFilter.newLongRange(key, value.longValue(), Long.MAX_VALUE, true, true) :
                    NumericRangeFilter.newDoubleRange(key, value.doubleValue(), Double.MAX_VALUE, true, true);
        default:
            throw new IllegalArgumentException("Unexpected relation: " + relation);
    }
}
 
Example #5
Source File: UserProfileDataFilterMapper.java    From adam with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Filter convertToLuceneSearchFilter(@Nonnull UserProfileDataFilter filter) {
    final BooleanFilter result = new BooleanFilter();
    final Filter include = toFilter(filter.getIncludingGroups());
    if (include != null) {
        result.add(include, MUST);
    }
    final Filter exclude = toFilter(filter.getExcludingGroups());
    if (exclude != null) {
        result.add(exclude, MUST_NOT);
    }
    return result;
}