Search in sources :

Example 1 with QueryExpr

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

the class QueryParserTest method testQuery.

private void testQuery(final String query, final String expected) {
    final QueryExpr expr = QueryParser.parse(query);
    assertNotNull(expr);
    assertEquals(expected, expr.toString());
}
Also used : QueryExpr(com.enonic.xp.query.expr.QueryExpr)

Example 2 with QueryExpr

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

the class ContentQueryNodeQueryTranslator method buildNodeQueryExpr.

private static QueryExpr buildNodeQueryExpr(final ContentQuery contentQuery) {
    final QueryExpr queryExpr = contentQuery.getQueryExpr();
    final CompareExpr contentPathRootExpr = CompareExpr.like(FieldExpr.from("_path"), ValueExpr.string(ContentNodeHelper.getContentRoot() + "/*"));
    if (queryExpr != null) {
        final ConstraintExpr newExpr = queryExpr.getConstraint() != null ? LogicalExpr.and(queryExpr.getConstraint(), contentPathRootExpr) : contentPathRootExpr;
        return QueryExpr.from(newExpr, queryExpr.getOrderList());
    }
    return QueryExpr.from(contentPathRootExpr);
}
Also used : ConstraintExpr(com.enonic.xp.query.expr.ConstraintExpr) QueryExpr(com.enonic.xp.query.expr.QueryExpr) CompareExpr(com.enonic.xp.query.expr.CompareExpr)

Example 3 with QueryExpr

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

the class SetNodeChildOrderCommand method orderChildNodes.

private void orderChildNodes(final Node parentNode) {
    final SearchResult result = nodeSearchService.query(NodeQuery.create().parent(parentNode.path()).query(new QueryExpr(parentNode.getChildOrder().getOrderExpressions())).size(NodeSearchService.GET_ALL_SIZE_FLAG).batchSize(BATCH_SIZE).searchMode(SearchMode.SEARCH).build(), SingleRepoSearchSource.from(ContextAccessor.current()));
    final NodeIds childNodeIds = NodeIds.from(result.getIds());
    final List<NodeManualOrderValueResolver.NodeIdOrderValue> orderedNodeIds = NodeManualOrderValueResolver.resolve(childNodeIds);
    for (final NodeManualOrderValueResolver.NodeIdOrderValue nodeIdOrderValue : orderedNodeIds) {
        final Node node = doGetById(nodeIdOrderValue.getNodeId());
        final Node editedNode = Node.create(node).manualOrderValue(nodeIdOrderValue.getManualOrderValue()).timestamp(Instant.now(CLOCK)).build();
        StoreNodeCommand.create(this).node(editedNode).build().execute();
    }
}
Also used : QueryExpr(com.enonic.xp.query.expr.QueryExpr) NodeIds(com.enonic.xp.node.NodeIds) Node(com.enonic.xp.node.Node) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 4 with QueryExpr

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

the class SecurityServiceImpl method findByUsername.

private User findByUsername(final IdProviderKey idProvider, final String username) {
    final CompareExpr idProviderExpr = CompareExpr.create(FieldExpr.from(PrincipalIndexPath.ID_PROVIDER_KEY), CompareExpr.Operator.EQ, ValueExpr.string(idProvider.toString()));
    final CompareExpr userNameExpr = CompareExpr.create(FieldExpr.from(PrincipalIndexPath.LOGIN_KEY), CompareExpr.Operator.EQ, ValueExpr.string(username));
    final QueryExpr query = QueryExpr.from(LogicalExpr.and(idProviderExpr, userNameExpr));
    final Nodes nodes = callWithContext(() -> {
        final FindNodesByQueryResult result = nodeService.findByQuery(NodeQuery.create().query(query).build());
        return this.nodeService.getByIds(result.getNodeIds());
    });
    if (nodes.getSize() > 1) {
        throw new IllegalArgumentException("Expected at most 1 user with username " + username + " in id provider " + idProvider);
    }
    return nodes.isEmpty() ? null : PrincipalNodeTranslator.userFromNode(nodes.first());
}
Also used : CompareExpr(com.enonic.xp.query.expr.CompareExpr) QueryExpr(com.enonic.xp.query.expr.QueryExpr) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Nodes(com.enonic.xp.node.Nodes)

Example 5 with QueryExpr

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

the class QueryBuilderFactoryTest method createQueryWithFilter.

@Test
public void createQueryWithFilter() throws Exception {
    final String expected = load("query_with_queryfilter.json");
    final ValueFilter queryFilter = ValueFilter.create().fieldName("myField").addValue(ValueFactory.newString("myValue1")).addValue(ValueFactory.newString("myValue2")).build();
    final QueryExpr query = QueryParser.parse("not( myField > 1) ");
    final QueryBuilder builtQuery = QueryBuilderFactory.newBuilder().queryExpr(query).addQueryFilter(queryFilter).fieldNameResolver(new SearchQueryFieldNameResolver()).build().create();
    final String expectedJson = cleanString(expected);
    final String actualJson = cleanString(builtQuery.toString());
    assertEquals(expectedJson, actualJson);
}
Also used : QueryExpr(com.enonic.xp.query.expr.QueryExpr) ValueFilter(com.enonic.xp.query.filter.ValueFilter) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) Test(org.junit.jupiter.api.Test)

Aggregations

QueryExpr (com.enonic.xp.query.expr.QueryExpr)13 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)4 CompareExpr (com.enonic.xp.query.expr.CompareExpr)4 Nodes (com.enonic.xp.node.Nodes)3 ConstraintExpr (com.enonic.xp.query.expr.ConstraintExpr)3 Node (com.enonic.xp.node.Node)2 NodeQuery (com.enonic.xp.node.NodeQuery)2 OrderExpr (com.enonic.xp.query.expr.OrderExpr)2 Filters (com.enonic.xp.query.filter.Filters)2 HighlightQuery (com.enonic.xp.query.highlight.HighlightQuery)2 Test (org.junit.jupiter.api.Test)2 ContentQuery (com.enonic.xp.content.ContentQuery)1 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 Value (com.enonic.xp.data.Value)1 NodeIds (com.enonic.xp.node.NodeIds)1 AggregationQueries (com.enonic.xp.query.aggregation.AggregationQueries)1 AggregationQuery (com.enonic.xp.query.aggregation.AggregationQuery)1 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)1 FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)1