Search in sources :

Example 1 with ValueExpr

use of com.enonic.xp.query.expr.ValueExpr in project xp by enonic.

the class RangeFunctionArgsFactory method create.

public static RangeFunctionArg create(final List<ValueExpr> arguments) {
    validateArguments(arguments);
    final String fieldName = arguments.get(FIELDNAME_INDEX).getValue().asString();
    final ValueExpr from = arguments.get(FROM_INDEX);
    final ValueExpr to = arguments.get(TO_INDEX);
    boolean includeFrom = false;
    boolean includeTo = false;
    if (arguments.size() >= 4) {
        includeFrom = arguments.get(INCLUDE_FROM_INDEX).getValue().asBoolean();
    }
    if (arguments.size() >= 5) {
        includeTo = arguments.get(INCLUDE_TO_INDEX).getValue().asBoolean();
    }
    if (isInstant(from.getValue(), to.getValue()) || isInstantString(from.getValue(), to.getValue())) {
        return createInstantArgs(fieldName, from, to, includeFrom, includeTo);
    }
    if (isNumeric(from.getValue(), to.getValue())) {
        return createNumericArgs(fieldName, from, to, includeFrom, includeTo);
    }
    return createStringArgs(fieldName, from, to, includeFrom, includeTo);
}
Also used : ValueExpr(com.enonic.xp.query.expr.ValueExpr)

Example 2 with ValueExpr

use of com.enonic.xp.query.expr.ValueExpr in project xp by enonic.

the class InExpressionBuilder method build.

public static QueryBuilder build(final CompareExpr compareExpr, final QueryFieldNameResolver resolver) {
    final String queryFieldName = resolver.resolve(compareExpr.getField().getFieldPath());
    final List<ValueExpr> values = compareExpr.getValues();
    if (values == null || values.size() == 0) {
        throw new IndexQueryBuilderException("Cannot build empty 'IN' statements");
    }
    BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    for (ValueExpr value : values) {
        boolQuery.should(TermExpressionBuilder.build(queryFieldName, value.getValue()));
    }
    return boolQuery;
}
Also used : ValueExpr(com.enonic.xp.query.expr.ValueExpr) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 3 with ValueExpr

use of com.enonic.xp.query.expr.ValueExpr in project xp by enonic.

the class AbstractQueryFieldNameResolver method resolve.

@Override
public String resolve(final CompareExpr compareExpr) {
    final FieldExpr field = compareExpr.getField();
    final String baseFieldName = IndexFieldNameNormalizer.normalize(field.getFieldPath());
    final ValueExpr firstValue = compareExpr.getFirstValue();
    if (firstValue == null) {
        return "";
    }
    return createValueTypeAwareFieldName(baseFieldName, firstValue.getValue());
}
Also used : ValueExpr(com.enonic.xp.query.expr.ValueExpr) FieldExpr(com.enonic.xp.query.expr.FieldExpr)

Example 4 with ValueExpr

use of com.enonic.xp.query.expr.ValueExpr in project xp by enonic.

the class FindNodeIdsByParentCommand method createParentFilter.

private void createParentFilter(final NodePath parentPath, final NodeQuery.Builder builder) {
    if (parentPath.isRoot()) {
        final ValueExpr parentPathExpr = ValueExpr.string("/*");
        builder.query(QueryExpr.from(CompareExpr.like(FieldExpr.from(NodeIndexPath.PARENT_PATH), parentPathExpr)));
    } else {
        final ValueExpr parentPathExpr = ValueExpr.string(parentPath + "/*");
        builder.query(QueryExpr.from(CompareExpr.like(FieldExpr.from(NodeIndexPath.PATH), parentPathExpr)));
    }
}
Also used : ValueExpr(com.enonic.xp.query.expr.ValueExpr)

Example 5 with ValueExpr

use of com.enonic.xp.query.expr.ValueExpr in project xp by enonic.

the class FunctionExpressionBuilderTest method test_fulltext.

@Test
public void test_fulltext() {
    List<ValueExpr> arguments = List.of(ValueExpr.string("myField"), ValueExpr.string("mySearchString"), ValueExpr.string("OR"));
    final QueryBuilder fulltext = FunctionExpressionBuilder.build(new FunctionExpr("fulltext", arguments));
    assertTrue(fulltext instanceof SimpleQueryStringBuilder);
}
Also used : ValueExpr(com.enonic.xp.query.expr.ValueExpr) FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) SimpleQueryStringBuilder(org.elasticsearch.index.query.SimpleQueryStringBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

ValueExpr (com.enonic.xp.query.expr.ValueExpr)5 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)2 FieldExpr (com.enonic.xp.query.expr.FieldExpr)1 FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)1 SimpleQueryStringBuilder (org.elasticsearch.index.query.SimpleQueryStringBuilder)1 Test (org.junit.jupiter.api.Test)1