Search in sources :

Example 1 with RegexPredicate

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);
    }
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) RegexPredicate(com.google.gerrit.server.index.RegexPredicate)

Aggregations

RegexPredicate (com.google.gerrit.server.index.RegexPredicate)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1