Search in sources :

Example 56 with NodeQuery

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

the class DateRangeAggregationTest method ranges_with_date_math_date.

@Test
public void ranges_with_date_math_date() throws Exception {
    final Instant anchor = Instant.parse("2014-12-10T10:00:00Z");
    createNode(anchor, "n1", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600), "n2", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 2), "n3", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 3), "n4", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 4), "n5", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 5), "n6", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(DateRangeAggregationQuery.create("myDateRange").fieldName("instant").addRange(DateRange.create().to("2014-12-10T10:00:00Z||-5h").build()).addRange(DateRange.create().from("2014-12-10T10:00:00.000Z||-5h").to("2014-12-10T10:00:00.000Z||-3h").build()).addRange(DateRange.create().from("2014-12-10T10:00:00Z||-3h").build()).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getAggregations().getSize());
    final BucketAggregation aggregation = (BucketAggregation) result.getAggregations().get("myDateRange");
    final Buckets buckets = aggregation.getBuckets();
    final Iterator<Bucket> iterator = buckets.iterator();
    verifyBucket(iterator.next(), 0);
    verifyBucket(iterator.next(), 2);
    verifyBucket(iterator.next(), 4);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) DateRangeBucket(com.enonic.xp.aggregation.DateRangeBucket) Bucket(com.enonic.xp.aggregation.Bucket) Instant(java.time.Instant) NodeQuery(com.enonic.xp.node.NodeQuery) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Buckets(com.enonic.xp.aggregation.Buckets) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 57 with NodeQuery

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

the class HistogramAggregationTest method intervals.

@Test
public void intervals() throws Exception {
    createNode(10d, "n1", NodePath.ROOT);
    createNode(20d, "n2", NodePath.ROOT);
    createNode(30d, "n3", NodePath.ROOT);
    createNode(40d, "n4", NodePath.ROOT);
    createNode(50d, "n5", NodePath.ROOT);
    createNode(60d, "n6", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(HistogramAggregationQuery.create("ten").fieldName("value").interval(10L).build()).addAggregationQuery(HistogramAggregationQuery.create("twenty").fieldName("value").interval(20L).build()).addAggregationQuery(HistogramAggregationQuery.create("fourty").fieldName("value").interval(40L).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(3, result.getAggregations().getSize());
    final BucketAggregation ten = (BucketAggregation) result.getAggregations().get("ten");
    final BucketAggregation twenty = (BucketAggregation) result.getAggregations().get("twenty");
    final BucketAggregation fourty = (BucketAggregation) result.getAggregations().get("fourty");
    assertEquals(6, ten.getBuckets().getSize());
    assertEquals(4, twenty.getBuckets().getSize());
    assertEquals(2, fourty.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 58 with NodeQuery

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

the class HistogramAggregationTest method order.

@Test
public void order() throws Exception {
    createNode(1d, "n1", NodePath.ROOT);
    createNode(2d, "n2", NodePath.ROOT);
    createNode(3d, "n3", NodePath.ROOT);
    createNode(10d, "n4", NodePath.ROOT);
    createNode(11d, "n5", NodePath.ROOT);
    createNode(20d, "n6", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(HistogramAggregationQuery.create("count_asc").fieldName("value").interval(10L).order(HistogramAggregationQuery.Order.COUNT_ASC).build()).addAggregationQuery(HistogramAggregationQuery.create("key_asc").fieldName("value").interval(20L).order(HistogramAggregationQuery.Order.KEY_ASC).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(2, result.getAggregations().getSize());
    final BucketAggregation countAsc = (BucketAggregation) result.getAggregations().get("count_asc");
    final BucketAggregation keyAsc = (BucketAggregation) result.getAggregations().get("key_asc");
    final Iterator<Bucket> countAsIterator = countAsc.getBuckets().iterator();
    long previous = 0;
    while (countAsIterator.hasNext()) {
        final long nextCount = countAsIterator.next().getDocCount();
        assertTrue(previous < nextCount);
        previous = nextCount;
    }
    final Iterator<Bucket> keyAscIterator = keyAsc.getBuckets().iterator();
    String key = null;
    while (keyAscIterator.hasNext()) {
        final String next = keyAscIterator.next().getKey();
        assertTrue(key == null || key.compareTo(next) < 0);
        key = next;
    }
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Bucket(com.enonic.xp.aggregation.Bucket) 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 59 with NodeQuery

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

the class FindNodePathByQueryTest method queryAndExpect.

private void queryAndExpect(final String queryString, final NodePaths expected) {
    final NodeQuery query = NodeQuery.create().query(QueryParser.parse(queryString)).build();
    final FindNodePathsByQueryResult result = this.nodeService.findNodePathsByQuery(query);
    assertEquals(expected, result.getPaths());
}
Also used : NodeQuery(com.enonic.xp.node.NodeQuery) FindNodePathsByQueryResult(com.enonic.xp.node.FindNodePathsByQueryResult)

Example 60 with NodeQuery

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

the class FindNodesByMultiRepoQueryCommandTest method no_access_in_one_repo.

@Test
public void no_access_in_one_repo() throws Exception {
    final Repository repo1 = createRepo(REPO_USER_1, "repo1");
    final Repository repo2 = createRepo(REPO_USER_2, "repo2");
    runInContext(REPO_USER_1, repo1.getId(), () -> createNode(NodePath.ROOT, "repo1Node"));
    runInContext(REPO_USER_2, repo2.getId(), () -> createNode(NodePath.ROOT, "repo2Node"));
    final SearchTargets targets = SearchTargets.create().add(createTarget(MASTER_BRANCH, REPO_USER_1, repo1.getId())).add(// repoUser2 has no access
    createTarget(MASTER_BRANCH, REPO_USER_1, repo2.getId())).build();
    final NodeQuery query = NodeQuery.create().parent(NodePath.ROOT).build();
    final FindNodesByMultiRepoQueryResult result = doQuery(query, targets);
    assertEquals(1L, result.getTotalHits());
    assertRepos(result, repo1.getId());
    assertBranches(result, MASTER_BRANCH);
}
Also used : FindNodesByMultiRepoQueryResult(com.enonic.xp.node.FindNodesByMultiRepoQueryResult) Repository(com.enonic.xp.repository.Repository) MultiRepoNodeQuery(com.enonic.xp.node.MultiRepoNodeQuery) NodeQuery(com.enonic.xp.node.NodeQuery) SearchTargets(com.enonic.xp.node.SearchTargets) Test(org.junit.jupiter.api.Test)

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