use of com.enonic.xp.aggregation.Bucket in project xp by enonic.
the class TermsAggregationsTest method size.
@Test
public void size() 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.DESC).orderType(TermsAggregationQuery.Type.DOC_COUNT).size(2).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(2, categoryAgg.getBuckets().getSize());
final Iterator<Bucket> iterator = categoryAgg.getBuckets().iterator();
Bucket next = iterator.next();
assertEquals("c2", next.getKey());
assertEquals(3, next.getDocCount());
next = iterator.next();
assertEquals("c1", next.getKey());
assertEquals(2, next.getDocCount());
}
use of com.enonic.xp.aggregation.Bucket 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);
}
use of com.enonic.xp.aggregation.Bucket in project xp by enonic.
the class NumericRangeAggregationTest method ranges.
@Test
public void ranges() throws Exception {
createNode(100d, "n1", NodePath.ROOT);
createNode(300d, "n2", NodePath.ROOT);
createNode(400d, "n3", NodePath.ROOT);
createNode(200d, "n4", NodePath.ROOT);
createNode(600d, "n5", NodePath.ROOT);
createNode(500d, "n6", NodePath.ROOT);
final NodeQuery query = NodeQuery.create().addAggregationQuery(NumericRangeAggregationQuery.create("myNumericRange").fieldName("numeric").addRange(NumericRange.create().to(150d).build()).addRange(NumericRange.create().from(150d).to(250d).build()).addRange(NumericRange.create().from(250d).to(350d).build()).addRange(NumericRange.create().from(350d).build()).build()).build();
FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(1, result.getAggregations().getSize());
final BucketAggregation aggregation = (BucketAggregation) result.getAggregations().get("myNumericRange");
final Buckets buckets = aggregation.getBuckets();
final Iterator<Bucket> iterator = buckets.iterator();
verifyBucket(iterator.next(), 1, null);
verifyBucket(iterator.next(), 1, null);
verifyBucket(iterator.next(), 1, null);
verifyBucket(iterator.next(), 3, null);
}
use of com.enonic.xp.aggregation.Bucket in project xp by enonic.
the class NumericRangeAggregationTest method keys.
@Test
public void keys() throws Exception {
createNode(100d, "n1", NodePath.ROOT);
createNode(200d, "n4", NodePath.ROOT);
createNode(300d, "n2", NodePath.ROOT);
createNode(400d, "n3", NodePath.ROOT);
createNode(500d, "n6", NodePath.ROOT);
createNode(600d, "n5", NodePath.ROOT);
final NodeQuery query = NodeQuery.create().addAggregationQuery(NumericRangeAggregationQuery.create("myNumericRange").fieldName("numeric").addRange(NumericRange.create().key("small").to(350d).build()).addRange(NumericRange.create().key("large").from(350d).build()).build()).build();
FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(1, result.getAggregations().getSize());
final BucketAggregation aggregation = (BucketAggregation) result.getAggregations().get("myNumericRange");
final Buckets buckets = aggregation.getBuckets();
final Iterator<Bucket> iterator = buckets.iterator();
verifyBucket(iterator.next(), 3, "small");
verifyBucket(iterator.next(), 3, "large");
}
use of com.enonic.xp.aggregation.Bucket in project xp by enonic.
the class StatsAggregationTest method terms_stats_aggregation.
@Test
public void terms_stats_aggregation() throws Exception {
createNode("c1", 2.0, "n1", NodePath.ROOT);
createNode("c1", 4.0, "n2", NodePath.ROOT);
createNode("c1", 6.0, "n3", NodePath.ROOT);
createNode("c1", 8.0, "n4", NodePath.ROOT);
createNode("c2", 2.0, "n5", NodePath.ROOT);
createNode("c2", 4.0, "n6", NodePath.ROOT);
createNode("c3", 2.0, "n7", NodePath.ROOT);
final NodeQuery query = NodeQuery.create().addAggregationQuery(TermsAggregationQuery.create("category").fieldName("category").orderDirection(TermsAggregationQuery.Direction.ASC).orderType(TermsAggregationQuery.Type.TERM).addSubQuery(StatsAggregationQuery.create("subquery").fieldName("other").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();
verifyStatsAggregation(bucketIterator.next(), "c1", 2d, 8d, 5d, 20d, 4d);
verifyStatsAggregation(bucketIterator.next(), "c2", 2d, 4d, 3d, 6d, 2d);
verifyStatsAggregation(bucketIterator.next(), "c3", 2d, 2d, 2d, 2d, 1d);
}
Aggregations