Search in sources :

Example 11 with Aggregation

use of com.enonic.xp.aggregation.Aggregation 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 12 with Aggregation

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

the class TermsAggregationsTest method order_doccount_asc.

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

Aggregations

Aggregation (com.enonic.xp.aggregation.Aggregation)12 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)12 Bucket (com.enonic.xp.aggregation.Bucket)8 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)7 NodeQuery (com.enonic.xp.node.NodeQuery)7 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)7 Test (org.junit.jupiter.api.Test)7 StatsAggregation (com.enonic.xp.aggregation.StatsAggregation)4 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)3 Buckets (com.enonic.xp.aggregation.Buckets)2