Search in sources :

Example 1 with NotPredicate

use of com.google.gerrit.index.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.index.query.TimestampRangePredicate) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) RegexpQuery(org.apache.lucene.search.RegexpQuery) LegacyNumericRangeQuery(org.apache.lucene.search.LegacyNumericRangeQuery) 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.index.query.NotPredicate) LongPoint(org.apache.lucene.document.LongPoint) IntPoint(org.apache.lucene.document.IntPoint) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Example 2 with NotPredicate

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

the class ChangeIndexRewriter method extractStatus.

private static EnumSet<Change.Status> extractStatus(Predicate<ChangeData> in) {
    if (in instanceof ChangeStatusPredicate) {
        Status status = ((ChangeStatusPredicate) in).getStatus();
        return status != null ? EnumSet.of(status) : null;
    } else if (in instanceof NotPredicate) {
        EnumSet<Status> s = extractStatus(in.getChild(0));
        return s != null ? EnumSet.complementOf(s) : null;
    } else if (in instanceof OrPredicate) {
        EnumSet<Change.Status> r = null;
        int childrenWithStatus = 0;
        for (int i = 0; i < in.getChildCount(); i++) {
            EnumSet<Status> c = extractStatus(in.getChild(i));
            if (c != null) {
                if (r == null) {
                    r = EnumSet.noneOf(Change.Status.class);
                }
                r.addAll(c);
                childrenWithStatus++;
            }
        }
        if (r != null && childrenWithStatus < in.getChildCount()) {
            // the child was used at the root of a query.
            return EnumSet.allOf(Change.Status.class);
        }
        return r;
    } else if (in instanceof AndPredicate) {
        EnumSet<Change.Status> r = null;
        for (int i = 0; i < in.getChildCount(); i++) {
            EnumSet<Change.Status> c = extractStatus(in.getChild(i));
            if (c != null) {
                if (r == null) {
                    r = EnumSet.allOf(Change.Status.class);
                }
                r.retainAll(c);
            }
        }
        return r;
    }
    return null;
}
Also used : Status(com.google.gerrit.entities.Change.Status) OrPredicate(com.google.gerrit.index.query.OrPredicate) EnumSet(java.util.EnumSet) ChangeStatusPredicate(com.google.gerrit.server.query.change.ChangeStatusPredicate) AndPredicate(com.google.gerrit.index.query.AndPredicate) Change(com.google.gerrit.entities.Change) NotPredicate(com.google.gerrit.index.query.NotPredicate)

Aggregations

NotPredicate (com.google.gerrit.index.query.NotPredicate)2 Change (com.google.gerrit.entities.Change)1 Status (com.google.gerrit.entities.Change.Status)1 AndPredicate (com.google.gerrit.index.query.AndPredicate)1 OrPredicate (com.google.gerrit.index.query.OrPredicate)1 QueryParseException (com.google.gerrit.index.query.QueryParseException)1 TimestampRangePredicate (com.google.gerrit.index.query.TimestampRangePredicate)1 ChangeStatusPredicate (com.google.gerrit.server.query.change.ChangeStatusPredicate)1 EnumSet (java.util.EnumSet)1 IntPoint (org.apache.lucene.document.IntPoint)1 LongPoint (org.apache.lucene.document.LongPoint)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 LegacyNumericRangeQuery (org.apache.lucene.search.LegacyNumericRangeQuery)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)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