Performs a project name substring search.

Search for changes whose project name contains query text as
substring using no operator for that.
E.g. Searching for just "gerrit is:open" will try to match
a project name by "gerrit" as substring and return all open
changes for this (or these) project.
This commit is contained in:
monica.dionisio
2010-08-27 11:46:33 -03:00
committed by Ulrik Sjölin
parent 3ea1d5567c
commit 7dfa0d2866
2 changed files with 29 additions and 2 deletions

View File

@@ -46,7 +46,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'::
@@ -87,7 +92,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]]

View File

@@ -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);
}
}