use of com.enonic.xp.aggregation.Buckets 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.Buckets in project xp by enonic.
the class QueryContentHandlerTest method setUpForMetricsAggregations.
private void setUpForMetricsAggregations(final SingleValueMetricAggregation aggregation) {
final List<Content> toAddContents = new ArrayList<>();
for (int i = 1; i <= 5; i++) {
final PropertyTree data = new PropertyTree();
data.addString("category", "books");
data.addString("productName", "product " + i);
data.addDouble("price", 10.0 * i);
final Content content = Content.create().id(ContentId.from("id" + i)).name("name" + i).displayName("My Content " + i).parentPath(ContentPath.from("/a/b")).modifier(PrincipalKey.from("user:system:admin")).modifiedTime(Instant.ofEpochSecond(0)).creator(PrincipalKey.from("user:system:admin")).createdTime(Instant.ofEpochSecond(0)).data(data).build();
toAddContents.add(content);
}
final Buckets bucket = Buckets.create().add(Bucket.create().key("books").docCount(5).addAggregations(Aggregations.from(aggregation)).build()).build();
final Contents contents = Contents.from(toAddContents);
final FindContentIdsByQueryResult findResult = FindContentIdsByQueryResult.create().hits(contents.getSize()).totalHits(5).contents(contents.getIds()).aggregations(Aggregations.from(BucketAggregation.bucketAggregation("products").buckets(bucket).build())).build();
Mockito.when(this.contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(findResult);
Mockito.when(this.contentService.getByIds(Mockito.isA(GetContentByIdsParams.class))).thenReturn(contents);
}
use of com.enonic.xp.aggregation.Buckets 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.Buckets 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.Buckets in project xp by enonic.
the class GeoDistanceAggregationTest method ranges.
@Test
public void ranges() throws Exception {
createNode(OSLO, "oslo", NodePath.ROOT);
createNode(BERLIN, "berlin", NodePath.ROOT);
createNode(NEW_YORK, "new-york", NodePath.ROOT);
createNode(TRONDHEIM, "trondheim", NodePath.ROOT);
createNode(MOSCOW, "moscow", NodePath.ROOT);
createNode(FREDRIKSTAD, "fredrikstad", NodePath.ROOT);
createNode(LONDON, "london", NodePath.ROOT);
final NodeQuery query = NodeQuery.create().addAggregationQuery(GeoDistanceAggregationQuery.create("myGeoDistance").fieldName("geoPoint").origin(OSLO).unit("km").addRange(DistanceRange.create().to(200.0).build()).addRange(DistanceRange.create().from(200.0).to(800.0).build()).addRange(DistanceRange.create().from(800.0).to(1600.0).build()).addRange(DistanceRange.create().from(1600.0).to(2400.0).build()).addRange(DistanceRange.create().from(2400.0).build()).build()).build();
FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(1, result.getAggregations().getSize());
final BucketAggregation aggregation = (BucketAggregation) result.getAggregations().get("myGeoDistance");
final Buckets buckets = aggregation.getBuckets();
final Iterator<Bucket> iterator = buckets.iterator();
// OSLO, FREDRIKSTAD
verifyBucket(iterator.next(), 2, null);
// TRONDHEIM
verifyBucket(iterator.next(), 1, null);
// BERLIN, LONDON
verifyBucket(iterator.next(), 2, null);
// MOSCOW
verifyBucket(iterator.next(), 1, null);
// NEW YORK
verifyBucket(iterator.next(), 1, null);
}
Aggregations