use of com.google.gerrit.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class ReviewerRecommender method baseRankingForEmptyQuery.
private Map<Account.Id, MutableDouble> baseRankingForEmptyQuery(double baseWeight) throws OrmException {
// Get the user's last 25 changes, check approvals
try {
List<ChangeData> result = internalChangeQuery.setLimit(25).setRequestedFields(ImmutableSet.of(ChangeField.REVIEWER.getName())).query(changeQueryBuilder.owner("self"));
Map<Account.Id, MutableDouble> suggestions = new HashMap<>();
for (ChangeData cd : result) {
for (PatchSetApproval approval : cd.currentApprovals()) {
Account.Id id = approval.getAccountId();
if (suggestions.containsKey(id)) {
suggestions.get(id).add(baseWeight);
} else {
suggestions.put(id, new MutableDouble(baseWeight));
}
}
}
return suggestions;
} catch (QueryParseException e) {
// Unhandled, because owner:self will never provoke a QueryParseException
log.error("Exception while suggesting reviewers", e);
return ImmutableMap.of();
}
}
use of com.google.gerrit.server.query.QueryParseException 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.query.QueryParseException in project gerrit by GerritCodeReview.
the class QueryGroups method apply.
@Override
public List<GroupInfo> apply(TopLevelResource resource) throws BadRequestException, MethodNotAllowedException, OrmException {
if (Strings.isNullOrEmpty(query)) {
throw new BadRequestException("missing query field");
}
GroupIndex searchIndex = indexes.getSearchIndex();
if (searchIndex == null) {
throw new MethodNotAllowedException("no group index");
}
if (start != 0) {
queryProcessor.setStart(start);
}
if (limit != 0) {
queryProcessor.setLimit(limit);
}
try {
QueryResult<AccountGroup> result = queryProcessor.query(queryBuilder.parse(query));
List<AccountGroup> groups = result.entities();
ArrayList<GroupInfo> groupInfos = Lists.newArrayListWithCapacity(groups.size());
json.addOptions(options);
for (AccountGroup group : groups) {
groupInfos.add(json.format(GroupDescriptions.forAccountGroup(group)));
}
if (!groupInfos.isEmpty() && result.more()) {
groupInfos.get(groupInfos.size() - 1)._moreGroups = true;
}
return groupInfos;
} catch (QueryParseException e) {
throw new BadRequestException(e.getMessage());
}
}
use of com.google.gerrit.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class FuzzyTopicPredicate method match.
@Override
public boolean match(final ChangeData cd) throws OrmException {
Change change = cd.change();
if (change == null) {
return false;
}
String t = change.getTopic();
if (t == null) {
return false;
}
try {
Predicate<ChangeData> thisId = new LegacyChangeIdPredicate(cd.getId());
Iterable<ChangeData> results = index.getSource(and(thisId, this), IndexedChangeQuery.oneResult()).read();
return !Iterables.isEmpty(results);
} catch (QueryParseException e) {
throw new OrmException(e);
}
}
use of com.google.gerrit.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class IsWatchedByPredicate method filters.
protected static List<Predicate<ChangeData>> filters(ChangeQueryBuilder.Arguments args, boolean checkIsVisible) throws QueryParseException {
List<Predicate<ChangeData>> r = new ArrayList<>();
ChangeQueryBuilder builder = new ChangeQueryBuilder(args);
for (ProjectWatchKey w : getWatches(args)) {
Predicate<ChangeData> f = null;
if (w.filter() != null) {
try {
f = builder.parse(w.filter());
if (QueryBuilder.find(f, IsWatchedByPredicate.class) != null) {
// another user is filtering on. :-)
continue;
}
} catch (QueryParseException e) {
continue;
}
}
Predicate<ChangeData> p;
if (w.project().equals(args.allProjectsName)) {
p = null;
} else {
p = builder.project(w.project().get());
}
if (p != null && f != null) {
r.add(and(p, f));
} else if (p != null) {
r.add(p);
} else if (f != null) {
r.add(f);
} else {
r.add(builder.status_open());
}
}
if (r.isEmpty()) {
return none();
} else if (checkIsVisible) {
return ImmutableList.of(or(r), builder.is_visible());
} else {
return ImmutableList.of(or(r));
}
}
Aggregations