Search in sources :

Example 1 with MinAggregationQuery

use of com.enonic.xp.query.aggregation.metric.MinAggregationQuery 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());
        }
    });
}
Also used : MinAggregationQuery(com.enonic.xp.query.aggregation.metric.MinAggregationQuery) ValueCountAggregationQuery(com.enonic.xp.query.aggregation.metric.ValueCountAggregationQuery) HashMap(java.util.HashMap) AggregationQueries(com.enonic.xp.query.aggregation.AggregationQueries) MaxAggregationQuery(com.enonic.xp.query.aggregation.metric.MaxAggregationQuery) Test(org.junit.jupiter.api.Test)

Example 2 with MinAggregationQuery

use of com.enonic.xp.query.aggregation.metric.MinAggregationQuery in project xp by enonic.

the class BucketAggregationQueryTest method generateSubQueries.

private List<AggregationQuery> generateSubQueries() {
    final MaxAggregationQuery query1 = MaxAggregationQuery.create("query1").build();
    final MinAggregationQuery query2 = MinAggregationQuery.create("query2").build();
    final StatsAggregationQuery query3 = StatsAggregationQuery.create("query3").build();
    final ValueCountAggregationQuery query4 = ValueCountAggregationQuery.create("query4").build();
    return Arrays.asList(query1, query2, query3, query4);
}
Also used : MinAggregationQuery(com.enonic.xp.query.aggregation.metric.MinAggregationQuery) ValueCountAggregationQuery(com.enonic.xp.query.aggregation.metric.ValueCountAggregationQuery) MaxAggregationQuery(com.enonic.xp.query.aggregation.metric.MaxAggregationQuery) StatsAggregationQuery(com.enonic.xp.query.aggregation.metric.StatsAggregationQuery)

Aggregations

MaxAggregationQuery (com.enonic.xp.query.aggregation.metric.MaxAggregationQuery)2 MinAggregationQuery (com.enonic.xp.query.aggregation.metric.MinAggregationQuery)2 ValueCountAggregationQuery (com.enonic.xp.query.aggregation.metric.ValueCountAggregationQuery)2 AggregationQueries (com.enonic.xp.query.aggregation.AggregationQueries)1 StatsAggregationQuery (com.enonic.xp.query.aggregation.metric.StatsAggregationQuery)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1