Search in sources :

Example 1 with LogicalExpr

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

the class ReorderChildNodeCommand method createFirstNodeBeforeInsertQuery.

private NodeQuery createFirstNodeBeforeInsertQuery(final Long nodeAfterOrderValue) {
    final CompareExpr orderGreaterThanNodeToMoveBefore = CompareExpr.gt(FieldExpr.from(NodeIndexPath.MANUAL_ORDER_VALUE), ValueExpr.number(nodeAfterOrderValue));
    final CompareExpr parentPathEqualToParent = CompareExpr.eq(FieldExpr.from(NodeIndexPath.PARENT_PATH), ValueExpr.string(parentNode.path().toString()));
    final LogicalExpr constraint = LogicalExpr.and(orderGreaterThanNodeToMoveBefore, parentPathEqualToParent);
    final FieldOrderExpr orderManuallyDesc = FieldOrderExpr.create(NodeIndexPath.MANUAL_ORDER_VALUE, OrderExpr.Direction.ASC);
    return NodeQuery.create().query(QueryExpr.from(constraint, orderManuallyDesc)).size(1).build();
}
Also used : FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) CompareExpr(com.enonic.xp.query.expr.CompareExpr) LogicalExpr(com.enonic.xp.query.expr.LogicalExpr)

Example 2 with LogicalExpr

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

the class PrincipalQueryNodeQueryTranslator method getQueryExpression.

private static QueryExpr getQueryExpression(final String query) {
    final String fields = String.join(",", DISPLAY_NAME_KEY, ALL_TEXT_FIELD_NAME);
    final FunctionExpr fullText = FunctionExpr.from("fulltext", ValueExpr.string(fields), ValueExpr.string(query), ValueExpr.string("AND"));
    final FunctionExpr nGram = FunctionExpr.from("ngram", ValueExpr.string(fields), ValueExpr.string(query), ValueExpr.string("AND"));
    final LogicalExpr fullTextOrNgram = LogicalExpr.or(new DynamicConstraintExpr(fullText), new DynamicConstraintExpr(nGram));
    return new QueryExpr(fullTextOrNgram, Collections.emptySet());
}
Also used : FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) QueryExpr(com.enonic.xp.query.expr.QueryExpr) LogicalExpr(com.enonic.xp.query.expr.LogicalExpr)

Aggregations

LogicalExpr (com.enonic.xp.query.expr.LogicalExpr)2 CompareExpr (com.enonic.xp.query.expr.CompareExpr)1 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)1 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)1 FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)1 QueryExpr (com.enonic.xp.query.expr.QueryExpr)1