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();
}
}
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());
}
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);
}
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);
}
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());
}
Aggregations