diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/index/ChangeField.java b/gerrit-server/src/main/java/com/google/gerrit/server/index/ChangeField.java index 62acf5bbcf..f214dce0b1 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/index/ChangeField.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/index/ChangeField.java @@ -49,7 +49,7 @@ import java.util.Set; */ public class ChangeField { /** Increment whenever making schema changes. */ - public static final int SCHEMA_VERSION = 14; + public static final int SCHEMA_VERSION = 15; /** Legacy change ID. */ public static final FieldDef LEGACY_ID = @@ -228,6 +228,22 @@ public class ChangeField { } }; + /** Set true if the change has a non-zero label score. */ + public static final FieldDef REVIEWED = + new FieldDef.Single( + "reviewed", FieldType.EXACT, false) { + @Override + public String get(ChangeData input, FillArgs args) + throws OrmException { + for (PatchSetApproval a : input.currentApprovals(args.db)) { + if (a.getValue() != 0) { + return "1"; + } + } + return null; + } + }; + public static String formatLabel(String label, int value) { return formatLabel(label, value, null); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/IsReviewedPredicate.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/IsReviewedPredicate.java index 639be517c7..6832e4e16c 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/IsReviewedPredicate.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/IsReviewedPredicate.java @@ -18,15 +18,16 @@ import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSetApproval; import com.google.gerrit.reviewdb.server.ReviewDb; -import com.google.gerrit.server.query.OperatorPredicate; +import com.google.gerrit.server.index.ChangeField; +import com.google.gerrit.server.index.IndexPredicate; import com.google.gwtorm.server.OrmException; import com.google.inject.Provider; -class IsReviewedPredicate extends OperatorPredicate { +class IsReviewedPredicate extends IndexPredicate { private final Provider dbProvider; IsReviewedPredicate(Provider dbProvider) { - super(ChangeQueryBuilder.FIELD_IS, "reviewed"); + super(ChangeField.REVIEWED, "1"); this.dbProvider = dbProvider; } @@ -51,4 +52,9 @@ class IsReviewedPredicate extends OperatorPredicate { public int getCost() { return 2; } + + @Override + public String toString() { + return "is:reviewed"; + } }