Search in sources :

Example 11 with BucketAggregation

use of com.enonic.xp.aggregation.BucketAggregation in project xp by enonic.

the class ContentDependenciesResolver method resolveInboundDependenciesAggregation.

private Collection<ContentDependenciesAggregation> resolveInboundDependenciesAggregation(final ContentId contentId) {
    if (contentId == null) {
        return new HashSet<>();
    }
    final FindContentIdsByQueryResult result = this.contentService.find(ContentQuery.create().queryFilter(BooleanFilter.create().must(IdFilter.create().fieldName(ContentIndexPath.REFERENCES.getPath()).value(contentId.toString()).build()).mustNot(IdFilter.create().fieldName(ContentIndexPath.ID.getPath()).value(contentId.toString()).build()).build()).aggregationQuery(TermsAggregationQuery.create("type").fieldName("type").orderDirection(TermsAggregationQuery.Direction.DESC).build()).build());
    final BucketAggregation bucketAggregation = (BucketAggregation) result.getAggregations().get("type");
    return bucketAggregation.getBuckets().getSet().stream().map(ContentDependenciesAggregation::new).collect(toList());
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) HashSet(java.util.HashSet)

Example 12 with BucketAggregation

use of com.enonic.xp.aggregation.BucketAggregation in project xp by enonic.

the class ValueCountAggregationTest method terms_stats_aggregation.

@Test
public void terms_stats_aggregation() throws Exception {
    createNode("c1", "n1", NodePath.ROOT);
    createNode("c1", "n2", NodePath.ROOT);
    createNode("c1", "n3", NodePath.ROOT);
    createNode("c1", "n4", NodePath.ROOT);
    createNode("c2", "n5", NodePath.ROOT);
    createNode("c2", "n6", NodePath.ROOT);
    createNode("c3", "n7", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(TermsAggregationQuery.create("category").fieldName("category").orderDirection(TermsAggregationQuery.Direction.ASC).orderType(TermsAggregationQuery.Type.TERM).addSubQuery(ValueCountAggregationQuery.create("subquery").fieldName("category").build()).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getAggregations().getSize());
    final Aggregation agg = result.getAggregations().get("category");
    assertTrue(agg instanceof BucketAggregation);
    final BucketAggregation categoryAgg = (BucketAggregation) agg;
    final Iterator<Bucket> bucketIterator = categoryAgg.getBuckets().iterator();
    verifyValueCount(bucketIterator.next(), "c1", 4d);
    verifyValueCount(bucketIterator.next(), "c2", 2d);
    verifyValueCount(bucketIterator.next(), "c3", 1d);
}
Also used : BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) SingleValueMetricAggregation(com.enonic.xp.aggregation.SingleValueMetricAggregation) Aggregation(com.enonic.xp.aggregation.Aggregation) 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 13 with BucketAggregation

use of com.enonic.xp.aggregation.BucketAggregation in project xp by enonic.

the class TermsAggregationsTest method nested_term_aggregation.

@Test
public void nested_term_aggregation() throws Exception {
    createNode("c1", "d1", "node1", NodePath.ROOT);
    createNode("c1", "d1", "node2", NodePath.ROOT);
    createNode("c1", "d2", "node3", NodePath.ROOT);
    createNode("c1", "d3", "node4", NodePath.ROOT);
    createNode("c2", "d1", "node5", NodePath.ROOT);
    createNode("c2", "d2", "node6", NodePath.ROOT);
    createNode("c2", "d2", "node7", NodePath.ROOT);
    createNode("c2", "d3", "node8", NodePath.ROOT);
    createNode("c3", "d1", "node9", NodePath.ROOT);
    createNode("c3", "d2", "node10", NodePath.ROOT);
    createNode("c3", "d3", "node11", NodePath.ROOT);
    createNode("c3", "d3", "node12", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(TermsAggregationQuery.create("category").fieldName("category").orderDirection(TermsAggregationQuery.Direction.ASC).orderType(TermsAggregationQuery.Type.TERM).addSubQuery(TermsAggregationQuery.create("subquery").fieldName("other").orderDirection(TermsAggregationQuery.Direction.ASC).orderType(TermsAggregationQuery.Type.TERM).build()).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getAggregations().getSize());
    final Aggregation agg = result.getAggregations().get("category");
    assertTrue(agg instanceof BucketAggregation);
    final BucketAggregation categoryAgg = (BucketAggregation) agg;
    final Iterator<Bucket> bucketIterator = categoryAgg.getBuckets().iterator();
    // Verify the number of values for each category, e.g in category
    // c1, there are 2 'd1's, 1 'd2' and 1 'd3'
    verifySubAggregation(bucketIterator.next(), "c1", 2, 1, 1);
    verifySubAggregation(bucketIterator.next(), "c2", 1, 2, 1);
    verifySubAggregation(bucketIterator.next(), "c3", 1, 1, 2);
}
Also used : BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Aggregation(com.enonic.xp.aggregation.Aggregation) 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 14 with BucketAggregation

use of com.enonic.xp.aggregation.BucketAggregation in project xp by enonic.

the class TermsAggregationsTest method order_doccount_asc.

@Test
public void order_doccount_asc() throws Exception {
    create_c1_c2_c3_with_2_3_1_category_hits();
    final NodeQuery query = NodeQuery.create().addAggregationQuery(TermsAggregationQuery.create("category").fieldName("category").orderDirection(TermsAggregationQuery.Direction.ASC).orderType(TermsAggregationQuery.Type.DOC_COUNT).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getAggregations().getSize());
    final Aggregation agg = result.getAggregations().get("category");
    assertTrue(agg instanceof BucketAggregation);
    final BucketAggregation categoryAgg = (BucketAggregation) agg;
    assertEquals(3, categoryAgg.getBuckets().getSize());
    final Iterator<Bucket> iterator = categoryAgg.getBuckets().iterator();
    Bucket next = iterator.next();
    assertEquals("c3", next.getKey());
    assertEquals(1, next.getDocCount());
    next = iterator.next();
    assertEquals("c1", next.getKey());
    assertEquals(2, next.getDocCount());
    next = iterator.next();
    assertEquals("c2", next.getKey());
    assertEquals(3, next.getDocCount());
}
Also used : BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Aggregation(com.enonic.xp.aggregation.Aggregation) 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 15 with BucketAggregation

use of com.enonic.xp.aggregation.BucketAggregation in project xp by enonic.

the class TermsAggregationsTest method verifySubAggregation.

private void verifySubAggregation(final Bucket parentBucket, String parentBucketKey, int first, int second, int third) {
    assertEquals(parentBucketKey, parentBucket.getKey(), "Wrong parent bucket key");
    assertEquals(1, parentBucket.getSubAggregations().getSize());
    final Aggregation subAgg = parentBucket.getSubAggregations().get("subquery");
    assertTrue(subAgg instanceof BucketAggregation);
    final BucketAggregation subBucketAgg = (BucketAggregation) subAgg;
    assertEquals(3, subBucketAgg.getBuckets().getSize());
    final Iterator<Bucket> subQueryIterator = subBucketAgg.getBuckets().iterator();
    Bucket nextSub = subQueryIterator.next();
    assertEquals("d1", nextSub.getKey());
    assertEquals(first, nextSub.getDocCount());
    nextSub = subQueryIterator.next();
    assertEquals("d2", nextSub.getKey());
    assertEquals(second, nextSub.getDocCount());
    nextSub = subQueryIterator.next();
    assertEquals("d3", nextSub.getKey());
    assertEquals(third, nextSub.getDocCount());
}
Also used : BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Aggregation(com.enonic.xp.aggregation.Aggregation) Bucket(com.enonic.xp.aggregation.Bucket) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation)

Aggregations

BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)24 NodeQuery (com.enonic.xp.node.NodeQuery)19 Test (org.junit.jupiter.api.Test)19 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)18 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)18 Bucket (com.enonic.xp.aggregation.Bucket)15 Aggregation (com.enonic.xp.aggregation.Aggregation)10 Buckets (com.enonic.xp.aggregation.Buckets)9 StatsAggregation (com.enonic.xp.aggregation.StatsAggregation)4 DateRangeBucket (com.enonic.xp.aggregation.DateRangeBucket)3 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)3 Instant (java.time.Instant)3 Aggregations (com.enonic.xp.aggregation.Aggregations)2 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)2 GeoDistanceRangeBucket (com.enonic.xp.aggregation.GeoDistanceRangeBucket)1 ContentId (com.enonic.xp.content.ContentId)1 ContentQuery (com.enonic.xp.content.ContentQuery)1 Contents (com.enonic.xp.content.Contents)1 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)1