Refactor checking if secondary index is enabled
Have one method to check if the secondary index is enabled which can be used from all search operators which require an index. Change-Id: Ic9d91be5c428aaeb89f926c1193cd4d93e943ca6 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -229,10 +229,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
|||||||
|
|
||||||
@Operator
|
@Operator
|
||||||
public Predicate<ChangeData> comment(String value) throws QueryParseException {
|
public Predicate<ChangeData> comment(String value) throws QueryParseException {
|
||||||
ChangeIndex index = args.indexes.getSearchIndex();
|
ChangeIndex index = requireIndex(FIELD_COMMENT, value);
|
||||||
if (index == null) {
|
|
||||||
throw error("secondary index must be enabled for comment:" + value);
|
|
||||||
}
|
|
||||||
return new CommentPredicate(args.dbProvider, index, value);
|
return new CommentPredicate(args.dbProvider, index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,15 +344,12 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
|||||||
@Operator
|
@Operator
|
||||||
public Predicate<ChangeData> file(String file) throws QueryParseException {
|
public Predicate<ChangeData> file(String file) throws QueryParseException {
|
||||||
if (file.startsWith("^")) {
|
if (file.startsWith("^")) {
|
||||||
if (allowFileRegex || args.indexes.getSearchIndex() != null) {
|
if (!allowFileRegex) {
|
||||||
return new RegexFilePredicate(args.dbProvider, args.patchListCache, file);
|
requireIndex(FIELD_FILE, file);
|
||||||
} else {
|
|
||||||
throw error("secondary index must be enabled for file:" + file);
|
|
||||||
}
|
}
|
||||||
|
return new RegexFilePredicate(args.dbProvider, args.patchListCache, file);
|
||||||
} else {
|
} else {
|
||||||
if (args.indexes.getSearchIndex() == null) {
|
requireIndex(FIELD_FILE, file);
|
||||||
throw error("secondary index must be enabled for file:" + file);
|
|
||||||
}
|
|
||||||
return new EqualsFilePredicate(args.dbProvider, args.patchListCache, file);
|
return new EqualsFilePredicate(args.dbProvider, args.patchListCache, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -671,4 +665,13 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
|||||||
}
|
}
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ChangeIndex requireIndex(String field, String value)
|
||||||
|
throws QueryParseException {
|
||||||
|
ChangeIndex idx = args.indexes.getSearchIndex();
|
||||||
|
if (idx == null) {
|
||||||
|
throw error("secondary index must be enabled for " + field + ":" + value);
|
||||||
|
}
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user