Support default query for groups
Change-Id: I9c8b2026bb872ae08f5435039280dfd1cb25433e Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -3,12 +3,26 @@
|
|||||||
Group queries only match internal groups. External groups and system
|
Group queries only match internal groups. External groups and system
|
||||||
groups are not included in the query result.
|
groups are not included in the query result.
|
||||||
|
|
||||||
|
== Basic Group Search
|
||||||
|
|
||||||
|
Similar to many popular search engines on the web, just enter some
|
||||||
|
text and let Gerrit figure out the meaning:
|
||||||
|
|
||||||
|
[options="header"]
|
||||||
|
|======================================================
|
||||||
|
|Description | Examples
|
||||||
|
|Name | Foo-Verifiers
|
||||||
|
|UUID | 6a1e70e1a88782771a91808c8af9bbb7a9871389
|
||||||
|
|Description | deprecated
|
||||||
|
|======================================================
|
||||||
|
|
||||||
[[search-operators]]
|
[[search-operators]]
|
||||||
== Search Operators
|
== Search Operators
|
||||||
|
|
||||||
Operators act as restrictions on the search. As more operators
|
Operators act as restrictions on the search. As more operators
|
||||||
are added to the same query string, they further restrict the
|
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, which will match against a variety of fields.
|
||||||
|
|
||||||
[[description]]
|
[[description]]
|
||||||
description:'DESCRIPTION'::
|
description:'DESCRIPTION'::
|
||||||
|
|||||||
@@ -14,15 +14,31 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.query.group;
|
package com.google.gerrit.server.query.group;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
import com.google.gerrit.server.index.FieldDef;
|
import com.google.gerrit.server.index.FieldDef;
|
||||||
import com.google.gerrit.server.index.IndexPredicate;
|
import com.google.gerrit.server.index.IndexPredicate;
|
||||||
import com.google.gerrit.server.index.group.GroupField;
|
import com.google.gerrit.server.index.group.GroupField;
|
||||||
import com.google.gerrit.server.query.Predicate;
|
import com.google.gerrit.server.query.Predicate;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class GroupPredicates {
|
public class GroupPredicates {
|
||||||
|
public static Predicate<AccountGroup> defaultPredicate(String query) {
|
||||||
|
// Adapt the capacity of this list when adding more default predicates.
|
||||||
|
List<Predicate<AccountGroup>> preds = Lists.newArrayListWithCapacity(5);
|
||||||
|
preds.add(uuid(new AccountGroup.UUID(query)));
|
||||||
|
preds.add(name(query));
|
||||||
|
preds.add(inname(query));
|
||||||
|
if (!Strings.isNullOrEmpty(query)) {
|
||||||
|
preds.add(description(query));
|
||||||
|
}
|
||||||
|
preds.add(owner(query));
|
||||||
|
return Predicate.or(preds);
|
||||||
|
}
|
||||||
|
|
||||||
public static Predicate<AccountGroup> uuid(AccountGroup.UUID uuid) {
|
public static Predicate<AccountGroup> uuid(AccountGroup.UUID uuid) {
|
||||||
return new GroupPredicate(GroupField.UUID,
|
return new GroupPredicate(GroupField.UUID,
|
||||||
GroupQueryBuilder.FIELD_UUID, uuid.get());
|
GroupQueryBuilder.FIELD_UUID, uuid.get());
|
||||||
|
|||||||
@@ -83,6 +83,11 @@ public class GroupQueryBuilder extends QueryBuilder<AccountGroup> {
|
|||||||
throw error("Invalid query");
|
throw error("Invalid query");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Predicate<AccountGroup> defaultField(String query) {
|
||||||
|
return GroupPredicates.defaultPredicate(query);
|
||||||
|
}
|
||||||
|
|
||||||
@Operator
|
@Operator
|
||||||
public Predicate<AccountGroup> limit(String query)
|
public Predicate<AccountGroup> limit(String query)
|
||||||
throws QueryParseException {
|
throws QueryParseException {
|
||||||
@@ -92,4 +97,5 @@ public class GroupQueryBuilder extends QueryBuilder<AccountGroup> {
|
|||||||
}
|
}
|
||||||
return new LimitPredicate<>(FIELD_LIMIT, limit);
|
return new LimitPredicate<>(FIELD_LIMIT, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,6 +252,18 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
|||||||
assertQuery("is:visibleToAll", groupThatIsVisibleToAll);
|
assertQuery("is:visibleToAll", groupThatIsVisibleToAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void byDefaultField() throws Exception {
|
||||||
|
GroupInfo group1 = createGroup(name("foo-group"));
|
||||||
|
GroupInfo group2 = createGroup(name("group2"));
|
||||||
|
GroupInfo group3 = createGroupWithDescription(name("group3"),
|
||||||
|
"decription that contains foo and the UUID of group2: " + group2.id);
|
||||||
|
|
||||||
|
assertQuery("non-existing");
|
||||||
|
assertQuery("foo", group1, group3);
|
||||||
|
assertQuery(group2.id, group2, group3);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withLimit() throws Exception {
|
public void withLimit() throws Exception {
|
||||||
GroupInfo group1 = createGroup(name("group1"));
|
GroupInfo group1 = createGroup(name("group1"));
|
||||||
|
|||||||
Reference in New Issue
Block a user