Search in sources :

Example 26 with NodeQuery

use of com.enonic.xp.node.NodeQuery in project xp by enonic.

the class FindNodesByQueryCommandTest_compare method compare_gt.

@Test
public void compare_gt() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.setDouble("my-value", 5.5);
    createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).data(data).build());
    final PropertyTree data2 = new PropertyTree();
    data2.setDouble("my-value", 10.0);
    final Node node2 = createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).data(data2).build());
    final NodeQuery query = NodeQuery.create().query(QueryExpr.from(CompareExpr.gt(FieldExpr.from(IndexPath.from("my-value")), ValueExpr.number(7)))).build();
    final FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getNodeIds().getSize());
    assertTrue(result.getNodeIds().contains(node2.id()));
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) Test(org.junit.jupiter.api.Test)

Example 27 with NodeQuery

use of com.enonic.xp.node.NodeQuery in project xp by enonic.

the class CleanUpAuditLogCommand method createQuery.

private NodeQuery createQuery() {
    final NodeQuery.Builder builder = NodeQuery.create().addQueryFilter(ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.toString()).addValue(ValueFactory.newString(AuditLogConstants.NODE_TYPE.toString())).build());
    final RangeFilter timeToFilter = RangeFilter.create().fieldName(AuditLogConstants.TIME.toString()).to(ValueFactory.newDateTime(until)).build();
    builder.addQueryFilter(timeToFilter);
    builder.addOrderBy(FieldOrderExpr.create(AuditLogConstants.TIME, OrderExpr.Direction.ASC)).size(BATCH_SIZE);
    return builder.build();
}
Also used : NodeQuery(com.enonic.xp.node.NodeQuery) RangeFilter(com.enonic.xp.query.filter.RangeFilter)

Example 28 with NodeQuery

use of com.enonic.xp.node.NodeQuery in project xp by enonic.

the class FindAuditLogCommand method runQuery.

private FindAuditLogResult runQuery() {
    final NodeQuery query = createQuery();
    if (query == null) {
        return FindAuditLogResult.empty();
    }
    FindNodesByQueryResult result = nodeService.findByQuery(query);
    List<AuditLog> logs = result.getNodeIds().stream().map(nodeService::getById).map(AuditLogSerializer::fromNode).collect(Collectors.toList());
    return FindAuditLogResult.create().total(result.getTotalHits()).hits(AuditLogs.from(logs)).build();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) AuditLog(com.enonic.xp.audit.AuditLog)

Example 29 with NodeQuery

use of com.enonic.xp.node.NodeQuery in project xp by enonic.

the class CreateIssueCommand method countTotalIssues.

private long countTotalIssues() {
    final IssueQuery query = IssueQuery.create().size(0).count(true).build();
    final NodeQuery nodeQuery = IssueQueryNodeQueryTranslator.translate(query);
    final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
    return result.getTotalHits();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) IssueQuery(com.enonic.xp.issue.IssueQuery)

Example 30 with NodeQuery

use of com.enonic.xp.node.NodeQuery in project xp by enonic.

the class FindeNodesByQueryCommandTest_like method queryAndExpect.

private void queryAndExpect(final String queryString, final int expected) {
    final NodeQuery query = NodeQuery.create().query(QueryParser.parse(queryString)).build();
    final FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(expected, result.getHits());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Aggregations

NodeQuery (com.enonic.xp.node.NodeQuery)73 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)58 Test (org.junit.jupiter.api.Test)44 Node (com.enonic.xp.node.Node)24 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)18 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)18 Bucket (com.enonic.xp.aggregation.Bucket)14 PropertyTree (com.enonic.xp.data.PropertyTree)11 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)10 Aggregation (com.enonic.xp.aggregation.Aggregation)7 Buckets (com.enonic.xp.aggregation.Buckets)6 FindNodesByMultiRepoQueryResult (com.enonic.xp.node.FindNodesByMultiRepoQueryResult)6 MultiRepoNodeQuery (com.enonic.xp.node.MultiRepoNodeQuery)6 Nodes (com.enonic.xp.node.Nodes)5 SearchTargets (com.enonic.xp.node.SearchTargets)5 Repository (com.enonic.xp.repository.Repository)5 DateRangeBucket (com.enonic.xp.aggregation.DateRangeBucket)3 ContentId (com.enonic.xp.content.ContentId)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)3 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2