use of com.enonic.xp.query.aggregation.TermsAggregationQuery in project xp by enonic.
the class QueryAggregationParamsTest method testTermsAggregation.
@Test
public void testTermsAggregation() {
final Map<String, Object> termsAggregation = new HashMap<>();
termsAggregation.put("field", "fieldName");
termsAggregation.put("order", "_count desc");
termsAggregation.put("size", 10);
termsAggregation.put("minDocCount", 5);
final Map<String, Object> aggregations = new HashMap<>();
aggregations.put("aggName", Collections.singletonMap("terms", termsAggregation));
final AggregationQueries result = new QueryAggregationParams().getAggregations(aggregations);
assertEquals(1, result.getSize());
assertTrue(result.first() instanceof TermsAggregationQuery);
final TermsAggregationQuery query = (TermsAggregationQuery) result.first();
assertNotNull(query);
assertEquals("fieldName", query.getFieldName());
assertEquals(5, query.getMinDocCount());
}
use of com.enonic.xp.query.aggregation.TermsAggregationQuery in project xp by enonic.
the class AggregationQueryBuilderFactory method doCreate.
private Set<AbstractAggregationBuilder> doCreate(final AggregationQueries aggregationQueries) {
Set<AbstractAggregationBuilder> aggregationBuilders = new HashSet<>();
for (final AggregationQuery aggregationQuery : aggregationQueries) {
final AbstractAggregationBuilder aggregationBuilder;
if (aggregationQuery instanceof TermsAggregationQuery) {
aggregationBuilder = new TermsAggregationQueryBuilderFactory(fieldNameResolver).create((TermsAggregationQuery) aggregationQuery);
} else if (aggregationQuery instanceof AbstractRangeAggregationQuery) {
aggregationBuilder = new RangeAggregationQueryBuilderFactory(fieldNameResolver).create((AbstractRangeAggregationQuery) aggregationQuery);
} else if (aggregationQuery instanceof AbstractHistogramAggregationQuery) {
aggregationBuilder = new HistogramAggregationQueryBuilderFactory(fieldNameResolver).create((AbstractHistogramAggregationQuery) aggregationQuery);
} else if (aggregationQuery instanceof MetricAggregationQuery) {
aggregationBuilder = new MetricAggregationQueryBuilderFactory(fieldNameResolver).create((MetricAggregationQuery) aggregationQuery);
} else {
throw new IllegalArgumentException("Unexpected aggregation type: " + aggregationQuery.getClass());
}
handleSubAggregations(aggregationQuery, aggregationBuilder);
aggregationBuilders.add(aggregationBuilder);
}
return aggregationBuilders;
}
use of com.enonic.xp.query.aggregation.TermsAggregationQuery in project xp by enonic.
the class QueryAggregationParamsTest method testTermsAggregationWithoutMinDocCount.
@Test
public void testTermsAggregationWithoutMinDocCount() {
final Map<String, Object> termsAggregation = new HashMap<>();
termsAggregation.put("field", "fieldName");
termsAggregation.put("order", "_count desc");
termsAggregation.put("size", 10);
final Map<String, Object> aggregations = new HashMap<>();
aggregations.put("aggName", Collections.singletonMap("terms", termsAggregation));
final AggregationQueries result = new QueryAggregationParams().getAggregations(aggregations);
assertEquals(1, result.getSize());
assertTrue(result.first() instanceof TermsAggregationQuery);
final TermsAggregationQuery query = (TermsAggregationQuery) result.first();
assertNotNull(query);
assertEquals("fieldName", query.getFieldName());
assertEquals(1, query.getMinDocCount());
}
Aggregations