Search in sources :

Example 51 with NodeQuery

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

the class FindNodesByQueryHandler method execute.

@Override
public Object execute() {
    final NodeQuery nodeQuery = createNodeQuery();
    final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
    return convert(result);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 52 with NodeQuery

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

the class CleanUpAuditLogCommand method doCleanUp.

private CleanUpAuditLogResult doCleanUp() {
    final CleanUpAuditLogResult.Builder result = CleanUpAuditLogResult.create();
    final NodeQuery query = createQuery();
    nodeService.refresh(RefreshMode.ALL);
    FindNodesByQueryResult nodesToDelete = nodeService.findByQuery(query);
    long hits = nodesToDelete.getHits();
    final long totalHits = nodesToDelete.getTotalHits();
    if (totalHits == 0) {
        return CleanUpAuditLogResult.empty();
    }
    listener.start(BATCH_SIZE);
    while (hits > 0) {
        for (NodeHit nodeHit : nodesToDelete.getNodeHits()) {
            result.deleted(nodeService.deleteById(nodeHit.getNodeId()).getSize());
            listener.processed();
        }
        nodesToDelete = nodeService.findByQuery(query);
        hits = nodesToDelete.getHits();
    }
    listener.finished();
    return result.build();
}
Also used : CleanUpAuditLogResult(com.enonic.xp.audit.CleanUpAuditLogResult) NodeHit(com.enonic.xp.node.NodeHit) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 53 with NodeQuery

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

the class SetPublishInfoCommand method findNodesWithoutPublishFirstAndFrom.

private NodeIds findNodesWithoutPublishFirstAndFrom(final NodeIds nodesToPush) {
    if (nodesToPush.isEmpty()) {
        return NodeIds.empty();
    }
    final BooleanFilter containPublishFirstAndFromFilter = BooleanFilter.create().must(ExistsFilter.create().fieldName(ContentIndexPath.PUBLISH_FIRST.getPath()).build()).must(ExistsFilter.create().fieldName(ContentIndexPath.PUBLISH_FROM.getPath()).build()).build();
    final NodeQuery query = NodeQuery.create().addQueryFilter(BooleanFilter.create().mustNot(containPublishFirstAndFromFilter).must(IdFilter.create().fieldName(ContentIndexPath.ID.getPath()).values(nodesToPush).build()).build()).size(NodeQuery.ALL_RESULTS_SIZE_FLAG).build();
    final FindNodesByQueryResult result = this.nodeService.findByQuery(query);
    return result.getNodeIds();
}
Also used : BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 54 with NodeQuery

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

the class DateHistogramAggregationsTest method intervals.

@Test
public void intervals() throws Exception {
    createNode(Instant.parse("2014-12-10T10:00:00Z"), "n1", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T10:30:00Z"), "n2", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T11:30:00Z"), "n3", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T12:45:00Z"), "n4", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T13:59:59Z"), "n5", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T14:01:00Z"), "n6", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(DateHistogramAggregationQuery.create("hour").format("Y-MM-DD").fieldName("instant").interval("1h").build()).addAggregationQuery(DateHistogramAggregationQuery.create("day").fieldName("instant").interval("1d").build()).addAggregationQuery(DateHistogramAggregationQuery.create("minute").fieldName("instant").interval("1m").build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(3, result.getAggregations().getSize());
    final BucketAggregation hour = (BucketAggregation) result.getAggregations().get("hour");
    final BucketAggregation day = (BucketAggregation) result.getAggregations().get("day");
    final BucketAggregation minute = (BucketAggregation) result.getAggregations().get("minute");
    assertEquals(5, hour.getBuckets().getSize());
    assertEquals(1, day.getBuckets().getSize());
    assertEquals(6, minute.getBuckets().getSize());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 55 with NodeQuery

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

the class DateHistogramAggregationsTest method format.

@Test
public void format() throws Exception {
    // Create 5 nodes with two hours between
    createNode(Instant.parse("2014-12-10T10:30:00Z"), "n1", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T10:40:00Z"), "n2", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(DateHistogramAggregationQuery.create("hhMM").fieldName("instant").interval("1h").format("HH:mm").build()).addAggregationQuery(DateHistogramAggregationQuery.create("mm").fieldName("instant").interval("1h").format("mm").build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(2, result.getAggregations().getSize());
    // The min-doc-count=0 will also return the empty fill-ins
    final BucketAggregation hhMM = (BucketAggregation) result.getAggregations().get("hhMM");
    final BucketAggregation mm = (BucketAggregation) result.getAggregations().get("mm");
    assertEquals(1, hhMM.getBuckets().getSize());
    assertEquals(1, mm.getBuckets().getSize());
    assertEquals("10:00", hhMM.getBuckets().first().getKey());
    assertEquals("00", mm.getBuckets().first().getKey());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

NodeQuery (com.enonic.xp.node.NodeQuery)74 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)59 Test (org.junit.jupiter.api.Test)45 Node (com.enonic.xp.node.Node)24 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)19 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)19 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)8 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 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)2