Search in sources :

Example 16 with BucketAggregation

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

the class TermsAggregationsTest method order_doccount_desc.

@Test
public void order_doccount_desc() 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).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("c2", next.getKey());
    assertEquals(3, next.getDocCount());
    next = iterator.next();
    assertEquals("c1", next.getKey());
    assertEquals(2, next.getDocCount());
    next = iterator.next();
    assertEquals("c3", next.getKey());
    assertEquals(1, 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 17 with BucketAggregation

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

the class DateHistogramAggregationsTest method intervals.

@Test
public void intervals() 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(DateHistogramAggregationQuery.create("hour").format("Y-MM-DD").fieldName("instant").interval("1h").build()).addAggregationQuery(DateHistogramAggregationQuery.create("day").fieldName("instant").interval("1d").build()).addAggregationQuery(DateHistogramAggregationQuery.create("minute").fieldName("instant").interval("1m").build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(3, result.getAggregations().getSize());
    final BucketAggregation hour = (BucketAggregation) result.getAggregations().get("hour");
    final BucketAggregation day = (BucketAggregation) result.getAggregations().get("day");
    final BucketAggregation minute = (BucketAggregation) result.getAggregations().get("minute");
    assertEquals(5, hour.getBuckets().getSize());
    assertEquals(1, day.getBuckets().getSize());
    assertEquals(6, minute.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)

Example 18 with BucketAggregation

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

the class DateHistogramAggregationsTest method format.

@Test
public void format() throws Exception {
    // Create 5 nodes with two hours between
    createNode(Instant.parse("2014-12-10T10:30:00Z"), "n1", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T10:40:00Z"), "n2", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(DateHistogramAggregationQuery.create("hhMM").fieldName("instant").interval("1h").format("HH:mm").build()).addAggregationQuery(DateHistogramAggregationQuery.create("mm").fieldName("instant").interval("1h").format("mm").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 hhMM = (BucketAggregation) result.getAggregations().get("hhMM");
    final BucketAggregation mm = (BucketAggregation) result.getAggregations().get("mm");
    assertEquals(1, hhMM.getBuckets().getSize());
    assertEquals(1, mm.getBuckets().getSize());
    assertEquals("10:00", hhMM.getBuckets().first().getKey());
    assertEquals("00", mm.getBuckets().first().getKey());
}
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)

Example 19 with BucketAggregation

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

the class DateRangeAggregationTest method ranges_with_date_math_date.

@Test
public void ranges_with_date_math_date() throws Exception {
    final Instant anchor = Instant.parse("2014-12-10T10:00:00Z");
    createNode(anchor, "n1", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600), "n2", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 2), "n3", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 3), "n4", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 4), "n5", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 5), "n6", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(DateRangeAggregationQuery.create("myDateRange").fieldName("instant").addRange(DateRange.create().to("2014-12-10T10:00:00Z||-5h").build()).addRange(DateRange.create().from("2014-12-10T10:00:00.000Z||-5h").to("2014-12-10T10:00:00.000Z||-3h").build()).addRange(DateRange.create().from("2014-12-10T10:00:00Z||-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(), 0);
    verifyBucket(iterator.next(), 2);
    verifyBucket(iterator.next(), 4);
}
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 20 with BucketAggregation

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

the class HistogramAggregationTest method intervals.

@Test
public void intervals() throws Exception {
    createNode(10d, "n1", NodePath.ROOT);
    createNode(20d, "n2", NodePath.ROOT);
    createNode(30d, "n3", NodePath.ROOT);
    createNode(40d, "n4", NodePath.ROOT);
    createNode(50d, "n5", NodePath.ROOT);
    createNode(60d, "n6", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(HistogramAggregationQuery.create("ten").fieldName("value").interval(10L).build()).addAggregationQuery(HistogramAggregationQuery.create("twenty").fieldName("value").interval(20L).build()).addAggregationQuery(HistogramAggregationQuery.create("fourty").fieldName("value").interval(40L).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(3, result.getAggregations().getSize());
    final BucketAggregation ten = (BucketAggregation) result.getAggregations().get("ten");
    final BucketAggregation twenty = (BucketAggregation) result.getAggregations().get("twenty");
    final BucketAggregation fourty = (BucketAggregation) result.getAggregations().get("fourty");
    assertEquals(6, ten.getBuckets().getSize());
    assertEquals(4, twenty.getBuckets().getSize());
    assertEquals(2, fourty.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 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