use of com.google.gerrit.server.index.IndexPredicate in project gerrit by GerritCodeReview.
the class ChangeIndexRewriter method rewriteImpl.
/**
* Rewrite a single predicate subtree.
*
* @param in predicate to rewrite.
* @param index index whose schema determines which fields are indexed.
* @param opts other query options.
* @param leafTerms number of leaf index query terms encountered so far.
* @return {@code null} if no part of this subtree can be queried in the index directly. {@code
* in} if this subtree and all its children can be queried directly in the index. Otherwise, a
* predicate that is semantically equivalent, with some of its subtrees wrapped to query the
* index directly.
* @throws QueryParseException if the underlying index implementation does not support this
* predicate.
*/
private Predicate<ChangeData> rewriteImpl(Predicate<ChangeData> in, ChangeIndex index, QueryOptions opts, MutableInteger leafTerms) throws QueryParseException {
if (isIndexPredicate(in, index)) {
if (++leafTerms.value > config.maxTerms()) {
throw new QueryParseException("too many terms in query");
}
return in;
} else if (in instanceof LimitPredicate) {
// and included that in their limit computation.
return new LimitPredicate<>(ChangeQueryBuilder.FIELD_LIMIT, opts.limit());
} else if (!isRewritePossible(in)) {
if (in instanceof IndexPredicate) {
throw new QueryParseException("Unsupported index predicate: " + in.toString());
}
// magic to indicate "in" cannot be rewritten
return null;
}
int n = in.getChildCount();
BitSet isIndexed = new BitSet(n);
BitSet notIndexed = new BitSet(n);
BitSet rewritten = new BitSet(n);
List<Predicate<ChangeData>> newChildren = Lists.newArrayListWithCapacity(n);
for (int i = 0; i < n; i++) {
Predicate<ChangeData> c = in.getChild(i);
Predicate<ChangeData> nc = rewriteImpl(c, index, opts, leafTerms);
if (nc == c) {
isIndexed.set(i);
newChildren.add(c);
} else if (nc == null) /* cannot rewrite c */
{
notIndexed.set(i);
newChildren.add(c);
} else {
rewritten.set(i);
newChildren.add(nc);
}
}
if (isIndexed.cardinality() == n) {
// All children are indexed, leave as-is for parent.
return in;
} else if (notIndexed.cardinality() == n) {
// Can't rewrite any children, so cannot rewrite in.
return null;
} else if (rewritten.cardinality() == n) {
// All children were rewritten.
return in.copy(newChildren);
}
return partitionChildren(in, newChildren, isIndexed, index, opts);
}
use of com.google.gerrit.server.index.IndexPredicate in project gerrit by GerritCodeReview.
the class ChangeIndexRewriter method rewriteImpl.
private Predicate<ChangeData> rewriteImpl(Predicate<ChangeData> in, QueryOptions opts) throws QueryParseException {
ChangeIndex index = indexes.getSearchIndex();
MutableInteger leafTerms = new MutableInteger();
Predicate<ChangeData> out = rewriteImpl(in, index, opts, leafTerms);
if (in == out || out instanceof IndexPredicate) {
return new IndexedChangeQuery(index, out, opts);
} else if (out == null) /* cannot rewrite */
{
return in;
} else {
return out;
}
}
Aggregations