Add search fields for # of changed lines.

Based off https://gerrit-review.googlesource.com/#/c/52190, but
implementing the final suggestion of indexing raw delta counts and
allowing arbitrary range queries off of those.

Also upgrade Lucene to 4.8.1 as this was released since the last
schema change (which was on 4.7.0).

Change-Id: Ia8a677e71e133f68eced4c5394df1d23efe7f12a
This commit is contained in:
Jeff Davidson
2014-05-21 18:48:33 -07:00
parent 063f658042
commit 45d0a772e1
19 changed files with 478 additions and 45 deletions

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2014 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.server.index.ChangeField;
import com.google.gerrit.server.index.IntegerRangePredicate;
import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException;
public class AddedPredicate extends IntegerRangePredicate<ChangeData> {
AddedPredicate(String value) throws QueryParseException {
super(ChangeField.ADDED, value);
}
@Override
protected int getValueInt(ChangeData changeData) throws OrmException {
return changeData.changedLines().insertions;
}
}

View File

@@ -75,6 +75,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
// NOTE: As new search operations are added, please keep the
// SearchSuggestOracle up to date.
public static final String FIELD_ADDED = "added";
public static final String FIELD_AFTER = "after";
public static final String FIELD_AGE = "age";
public static final String FIELD_BEFORE = "before";
@@ -83,6 +84,8 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
public static final String FIELD_COMMENT = "comment";
public static final String FIELD_COMMIT = "commit";
public static final String FIELD_CONFLICTS = "conflicts";
public static final String FIELD_DELETED = "deleted";
public static final String FIELD_DELTA = "delta";
public static final String FIELD_DRAFTBY = "draftby";
public static final String FIELD_FILE = "file";
public static final String FIELD_IS = "is";
@@ -676,6 +679,30 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
return sortkey_before(sortKey);
}
@Operator
public Predicate<ChangeData> added(String value)
throws QueryParseException {
return new AddedPredicate(value);
}
@Operator
public Predicate<ChangeData> deleted(String value)
throws QueryParseException {
return new DeletedPredicate(value);
}
@Operator
public Predicate<ChangeData> size(String value)
throws QueryParseException {
return delta(value);
}
@Operator
public Predicate<ChangeData> delta(String value)
throws QueryParseException {
return new DeltaPredicate(value);
}
@Override
protected Predicate<ChangeData> defaultField(String query) {
if (query.startsWith("refs/")) {

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2014 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.server.index.ChangeField;
import com.google.gerrit.server.index.IntegerRangePredicate;
import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException;
public class DeletedPredicate extends IntegerRangePredicate<ChangeData> {
DeletedPredicate(String value) throws QueryParseException {
super(ChangeField.DELETED, value);
}
@Override
protected int getValueInt(ChangeData changeData) throws OrmException {
return changeData.changedLines().deletions;
}
}

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2014 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.server.index.ChangeField;
import com.google.gerrit.server.index.IntegerRangePredicate;
import com.google.gerrit.server.query.QueryParseException;
import com.google.gerrit.server.query.change.ChangeData.ChangedLines;
import com.google.gwtorm.server.OrmException;
public class DeltaPredicate extends IntegerRangePredicate<ChangeData> {
DeltaPredicate(String value) throws QueryParseException {
super(ChangeField.DELTA, value);
}
@Override
protected int getValueInt(ChangeData changeData) throws OrmException {
ChangedLines changedLines = changeData.changedLines();
return changedLines.insertions + changedLines.deletions;
}
}

View File

@@ -24,12 +24,12 @@ import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.query.OrPredicate;
import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.util.LabelVote;
import com.google.gerrit.server.util.RangeUtil;
import com.google.gerrit.server.util.RangeUtil.Range;
import com.google.inject.Provider;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LabelPredicate extends OrPredicate<ChangeData> {
private static final int MAX_LABEL_VALUE = 4;
@@ -102,43 +102,28 @@ public class LabelPredicate extends OrPredicate<ChangeData> {
// Try next format.
}
Range range;
if (parsed == null) {
Matcher m = Pattern.compile("(>|>=|=|<|<=)([+-]?\\d+)$").matcher(v);
if (m.find()) {
parsed = new Parsed(v.substring(0, m.start()), m.group(1),
value(m.group(2)));
} else {
parsed = new Parsed(v, "=", 1);
range = RangeUtil.getRange(v, -MAX_LABEL_VALUE, MAX_LABEL_VALUE);
if (range == null) {
range = new Range(v, 1, 1);
}
} else {
range = RangeUtil.getRange(
parsed.label,
parsed.test,
parsed.expVal,
-MAX_LABEL_VALUE,
MAX_LABEL_VALUE);
}
String prefix = range.prefix;
int min = range.min;
int max = range.max;
int min, max;
switch (parsed.test) {
case "=":
default:
min = max = parsed.expVal;
break;
case ">":
min = parsed.expVal + 1;
max = MAX_LABEL_VALUE;
break;
case ">=":
min = parsed.expVal;
max = MAX_LABEL_VALUE;
break;
case "<":
min = -MAX_LABEL_VALUE;
max = parsed.expVal - 1;
break;
case "<=":
min = -MAX_LABEL_VALUE;
max = parsed.expVal;
break;
}
List<Predicate<ChangeData>> r =
Lists.newArrayListWithCapacity(max - min + 1);
for (int i = min; i <= max; i++) {
r.add(onePredicate(args, parsed.label, i));
r.add(onePredicate(args, prefix, i));
}
return r;
}
@@ -152,13 +137,6 @@ public class LabelPredicate extends OrPredicate<ChangeData> {
}
}
private static int value(String value) {
if (value.startsWith("+")) {
value = value.substring(1);
}
return Integer.parseInt(value);
}
private static Predicate<ChangeData> noLabelQuery(Args args, String label) {
List<Predicate<ChangeData>> r =
Lists.newArrayListWithCapacity(2 * MAX_LABEL_VALUE);