use of com.google.gerrit.server.index.RegexPredicate in project gerrit by GerritCodeReview.
the class ElasticQueryBuilder method exactQuery.
private <T> QueryBuilder exactQuery(IndexPredicate<T> p) {
String name = p.getField().getName();
String value = p.getValue();
if (value.isEmpty()) {
return new BoolQueryBuilder().mustNot(QueryBuilders.existsQuery(name));
} else if (p instanceof RegexPredicate) {
if (value.startsWith("^")) {
value = value.substring(1);
}
if (value.endsWith("$") && !value.endsWith("\\$") && !value.endsWith("\\\\$")) {
value = value.substring(0, value.length() - 1);
}
return QueryBuilders.regexpQuery(name + ".key", value);
} else {
return QueryBuilders.termQuery(name + ".key", value);
}
}
Aggregations