Search in sources :

Example 1 with BucketAggregation

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

the class AggregationMapper method serializeAggregations.

private static void serializeAggregations(final MapGenerator gen, final Aggregations value) {
    for (Aggregation aggregation : value) {
        gen.map(aggregation.getName());
        if (aggregation instanceof BucketAggregation) {
            final Buckets buckets = ((BucketAggregation) aggregation).getBuckets();
            serializeBuckets(gen, buckets);
        } else if (aggregation instanceof StatsAggregation) {
            final StatsAggregation statsAggregation = ((StatsAggregation) aggregation);
            serializeStatsAggregation(gen, statsAggregation);
        }
        gen.end();
    }
}
Also used : BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Aggregation(com.enonic.xp.aggregation.Aggregation) StatsAggregation(com.enonic.xp.aggregation.StatsAggregation) StatsAggregation(com.enonic.xp.aggregation.StatsAggregation) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Buckets(com.enonic.xp.aggregation.Buckets)

Example 2 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 3 with BucketAggregation

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

the class DateRangeAggregationTest method ranges.

@Test
public void ranges() 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(DateRangeAggregationQuery.create("myDateRange").fieldName("instant").addRange(DateRange.create().to(Instant.parse("2014-12-10T11:00:00Z")).build()).addRange(DateRange.create().from(Instant.parse("2014-12-10T11:00:00Z")).to(Instant.parse("2014-12-10T14:00:00Z")).build()).addRange(DateRange.create().from(Instant.parse("2014-12-10T14:00:00Z")).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(), 2);
    verifyBucket(iterator.next(), 3);
    verifyBucket(iterator.next(), 1);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) DateRangeBucket(com.enonic.xp.aggregation.DateRangeBucket) Bucket(com.enonic.xp.aggregation.Bucket) 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 4 with BucketAggregation

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

the class DateRangeAggregationTest method ranges_with_date_math.

@Test
public void ranges_with_date_math() throws Exception {
    final Instant now = Instant.now();
    createNode(now, "n1", NodePath.ROOT);
    createNode(now.plusSeconds(-3600), "n2", NodePath.ROOT);
    createNode(now.plusSeconds(-3600 * 2), "n3", NodePath.ROOT);
    createNode(now.plusSeconds(-3600 * 3), "n4", NodePath.ROOT);
    createNode(now.plusSeconds(-3600 * 4), "n5", NodePath.ROOT);
    createNode(now.plusSeconds(-3600 * 5), "n6", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(DateRangeAggregationQuery.create("myDateRange").fieldName("instant").addRange(DateRange.create().to("now-5h").build()).addRange(DateRange.create().from("now-5h").to("now-3h").build()).addRange(DateRange.create().from("now-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(), 1);
    verifyBucket(iterator.next(), 2);
    verifyBucket(iterator.next(), 3);
}
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 5 with BucketAggregation

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

the class DateHistogramAggregationsTest method min_doc_count.

@Test
public void min_doc_count() throws Exception {
    // Create 5 nodes with two hours between
    createNode(Instant.parse("2014-12-10T10:00:00Z"), "n1", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T12:00:00Z"), "n2", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T14:00:00Z"), "n3", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T16:00:59Z"), "n4", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T18:00:00Z"), "n5", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(DateHistogramAggregationQuery.create("dateHistogramWithZero").fieldName("instant").interval("1h").minDocCount(0L).build()).addAggregationQuery(DateHistogramAggregationQuery.create("dateHistogramWithDefault").fieldName("instant").interval("1h").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 zeroDocCount = (BucketAggregation) result.getAggregations().get("dateHistogramWithZero");
    final BucketAggregation defaultDocCount = (BucketAggregation) result.getAggregations().get("dateHistogramWithDefault");
    assertEquals(9, zeroDocCount.getBuckets().getSize());
    assertEquals(5, defaultDocCount.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)

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 Instant (java.time.Instant)3 Aggregations (com.enonic.xp.aggregation.Aggregations)2 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)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