Support 'comment' query operator to search for inline/summary comments

Change-Id: I9b073cbb6acc90aac3165643ca36ae5ff6fc7fdc
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-06-27 04:52:06 +02:00
parent 122ecd55fc
commit ceb12e007b
4 changed files with 94 additions and 1 deletions

View File

@@ -79,6 +79,7 @@ public class SearchSuggestOracle extends HighlightSuggestOracle {
suggestions.add("reviewerin:");
suggestions.add("commit:");
suggestions.add("comment:");
suggestions.add("project:");
suggestions.add("branch:");
suggestions.add("topic:");

View File

@@ -18,6 +18,8 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.client.TrackingId;
@@ -47,7 +49,7 @@ import java.util.Set;
*/
public class ChangeField {
/** Increment whenever making schema changes. */
public static final int SCHEMA_VERSION = 12;
public static final int SCHEMA_VERSION = 13;
/** Legacy change ID. */
public static final FieldDef<ChangeData, Integer> LEGACY_ID =
@@ -249,6 +251,24 @@ public class ChangeField {
}
};
/** Summary or inline comment. */
public static final FieldDef<ChangeData, Iterable<String>> COMMENT =
new FieldDef.Repeatable<ChangeData, String>(ChangeQueryBuilder.FIELD_COMMENT,
FieldType.FULL_TEXT, false) {
@Override
public Iterable<String> get(ChangeData input, FillArgs args)
throws OrmException {
Set<String> r = Sets.newHashSet();
for (PatchLineComment c : input.comments(args.db)) {
r.add(c.getMessage());
}
for (ChangeMessage m : input.messages(args.db)) {
r.add(m.getMessage());
}
return r;
}
};
public static final ImmutableMap<String, FieldDef<ChangeData, ?>> ALL;
static {

View File

@@ -80,6 +80,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
public static final String FIELD_AGE = "age";
public static final String FIELD_BRANCH = "branch";
public static final String FIELD_CHANGE = "change";
public static final String FIELD_COMMENT = "comment";
public static final String FIELD_COMMIT = "commit";
public static final String FIELD_DRAFTBY = "draftby";
public static final String FIELD_FILE = "file";
@@ -200,6 +201,14 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
throw new IllegalArgumentException();
}
@Operator
public Predicate<ChangeData> comment(String value) throws QueryParseException {
if (args.index == ChangeIndex.DISABLED) {
throw error("secondary index must be enabled for comment:" + value);
}
return new CommentPredicate(args.dbProvider, args.index, value);
}
@Operator
public Predicate<ChangeData> status(String statusName) {
if ("open".equals(statusName)) {

View File

@@ -0,0 +1,63 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.index.ChangeField;
import com.google.gerrit.server.index.ChangeIndex;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Provider;
class CommentPredicate extends IndexPredicate<ChangeData> {
private final Provider<ReviewDb> db;
private final ChangeIndex index;
CommentPredicate(Provider<ReviewDb> db, ChangeIndex index, String value) {
super(ChangeField.COMMENT, value);
this.db = db;
this.index = index;
}
@SuppressWarnings("unchecked")
@Override
public boolean match(ChangeData object) throws OrmException {
try {
for (ChangeData cData : index.getSource(
Predicate.and(new LegacyChangeIdPredicate(db, object.getId()), this))
.read()) {
if (cData.getId().equals(object.getId())) {
return true;
}
}
} catch (QueryParseException e) {
throw new OrmException(e);
}
return false;
}
@Override
public int getCost() {
return 1;
}
@Override
public boolean isIndexOnly() {
return true;
}
}