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