Merge "Performs a project name substring search."
This commit is contained in:
@@ -44,7 +44,12 @@ Search Operators
|
||||
|
||||
Operators act as restrictions on the search. As more operators
|
||||
are added to the same query string, they further restrict the
|
||||
returned results.
|
||||
returned results. Search can also be performed by typing only a
|
||||
text with no operator. It will try to match a project name by
|
||||
substring.
|
||||
|
||||
E.g. Searching for just "gerrit is:starred" will try to match a
|
||||
project name by "gerrit" as substring.
|
||||
|
||||
[[age]]
|
||||
age:'AGE'::
|
||||
@@ -85,7 +90,7 @@ Changes where 'SHA1' is one of the patch sets of the change.
|
||||
[[project]]
|
||||
project:'PROJECT'::
|
||||
+
|
||||
Changes occuring in 'PROJECT'. If 'PROJECT' starts with `^` it
|
||||
Changes occuring in 'PROJECT'. If 'PROJECT' starts with `^` it
|
||||
matches project names by regular expression.
|
||||
|
||||
[[branch]]
|
||||
|
@@ -484,6 +484,28 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
return label(query);
|
||||
|
||||
} else {
|
||||
// Try to match a project name by substring query.
|
||||
final List<ProjectPredicate> predicate =
|
||||
new ArrayList<ProjectPredicate>();
|
||||
try {
|
||||
for (final Project p : args.dbProvider.get().projects().all()) {
|
||||
if (p.getName().toLowerCase().contains(query.toLowerCase())) {
|
||||
predicate.add(new ProjectPredicate(args.dbProvider, p.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
// If two or more projects contains "query" as substring create an
|
||||
// OrPredicate holding predicates for all these projects, otherwise if
|
||||
// only one contains that, return only that one predicate by itself.
|
||||
if (predicate.size() == 1) {
|
||||
return predicate.get(0);
|
||||
} else if (predicate.size() > 1) {
|
||||
return Predicate.or(predicate);
|
||||
}
|
||||
} catch (OrmException e) {
|
||||
throw error("Cannot lookup project.", e);
|
||||
}
|
||||
|
||||
throw error("Unsupported query:" + query);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user