Search in sources :

Example 1 with NotPredicate

use of com.google.gerrit.server.query.NotPredicate in project gerrit by GerritCodeReview.

the class QueryBuilder method and.

private Query and(Predicate<V> p) throws QueryParseException {
    try {
        BooleanQuery.Builder b = new BooleanQuery.Builder();
        List<Query> not = Lists.newArrayListWithCapacity(p.getChildCount());
        for (int i = 0; i < p.getChildCount(); i++) {
            Predicate<V> c = p.getChild(i);
            if (c instanceof NotPredicate) {
                Predicate<V> n = c.getChild(0);
                if (n instanceof TimestampRangePredicate) {
                    b.add(notTimestamp((TimestampRangePredicate<V>) n), MUST);
                } else {
                    not.add(toQuery(n));
                }
            } else {
                b.add(toQuery(c), MUST);
            }
        }
        for (Query q : not) {
            b.add(q, MUST_NOT);
        }
        return b.build();
    } catch (BooleanQuery.TooManyClauses e) {
        throw new QueryParseException("cannot create query for index: " + p, e);
    }
}
Also used : TimestampRangePredicate(com.google.gerrit.server.index.TimestampRangePredicate) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) NumericRangeQuery(org.apache.lucene.search.NumericRangeQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) NotPredicate(com.google.gerrit.server.query.NotPredicate) QueryParseException(com.google.gerrit.server.query.QueryParseException)

Aggregations

TimestampRangePredicate (com.google.gerrit.server.index.TimestampRangePredicate)1 NotPredicate (com.google.gerrit.server.query.NotPredicate)1 QueryParseException (com.google.gerrit.server.query.QueryParseException)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 NumericRangeQuery (org.apache.lucene.search.NumericRangeQuery)1 PrefixQuery (org.apache.lucene.search.PrefixQuery)1 Query (org.apache.lucene.search.Query)1 RegexpQuery (org.apache.lucene.search.RegexpQuery)1 TermQuery (org.apache.lucene.search.TermQuery)1 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)1