use of com.enonic.xp.query.aggregation.AggregationQueries in project xp by enonic.
the class QueryAggregationParams method getAggregations.
public AggregationQueries getAggregations(final Map<String, Object> aggregationsMap) {
if (aggregationsMap == null) {
return AggregationQueries.empty();
}
final AggregationQueries.Builder aggregations = AggregationQueries.create();
aggregationsMap.forEach((name, aggregationQueryMap) -> {
final AggregationQuery aggregationQuery = aggregationQueryFromParams(name, (Map<String, Object>) aggregationQueryMap);
if (aggregationQuery != null) {
aggregations.add(aggregationQuery);
}
});
return aggregations.build();
}
use of com.enonic.xp.query.aggregation.AggregationQueries 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.AggregationQueries in project xp by enonic.
the class QueryAggregationParamsTest method testMetricAggregations.
@Test
public void testMetricAggregations() {
final Map<String, Object> aggregations = new HashMap<>();
aggregations.put("maxPrice", createMetricAggregationAsMap("max", "fieldName1"));
aggregations.put("minPrice", createMetricAggregationAsMap("min", "fieldName2"));
aggregations.put("countNodesWithNonEmptyPrice", createMetricAggregationAsMap("count", "fieldName3"));
final AggregationQueries result = new QueryAggregationParams().getAggregations(aggregations);
assertEquals(3, result.getSize());
result.forEach(aggregationQuery -> {
if (aggregationQuery instanceof MaxAggregationQuery) {
assertEquals("maxPrice", aggregationQuery.getName());
assertEquals("fieldName1", ((MaxAggregationQuery) aggregationQuery).getFieldName());
} else if (aggregationQuery instanceof MinAggregationQuery) {
assertEquals("minPrice", aggregationQuery.getName());
assertEquals("fieldName2", ((MinAggregationQuery) aggregationQuery).getFieldName());
} else {
assertEquals("countNodesWithNonEmptyPrice", aggregationQuery.getName());
assertEquals("fieldName3", ((ValueCountAggregationQuery) aggregationQuery).getFieldName());
}
});
}
use of com.enonic.xp.query.aggregation.AggregationQueries 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());
}
use of com.enonic.xp.query.aggregation.AggregationQueries in project xp by enonic.
the class AbstractFindNodesQueryHandler method createNodeQuery.
NodeQuery createNodeQuery() {
final int start = valueOrDefault(this.start, 0);
final int count = valueOrDefault(this.count, 10);
final QueryExpr queryExpr = QueryExpr.from(buildConstraintExpr(), buildOrderExpr());
final Filters filters = JsonToFilterMapper.create(this.filters);
final AggregationQueries aggregations = new QueryAggregationParams().getAggregations(this.aggregations);
final SuggestionQueries suggestions = new QuerySuggestionParams().getSuggestions(this.suggestions);
final HighlightQuery highlight = new QueryHighlightParams().getHighlightQuery(this.highlight);
return NodeQuery.create().from(start).size(count).addAggregationQueries(aggregations).addSuggestionQueries(suggestions).highlight(highlight).query(queryExpr).addQueryFilters(filters).explain(this.explain).build();
}
Aggregations