Search in sources :

Example 1 with AggregationQuery

use of com.enonic.xp.query.aggregation.AggregationQuery 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();
}
Also used : BucketAggregationQuery(com.enonic.xp.query.aggregation.BucketAggregationQuery) MinAggregationQuery(com.enonic.xp.query.aggregation.metric.MinAggregationQuery) HistogramAggregationQuery(com.enonic.xp.query.aggregation.HistogramAggregationQuery) NumericRangeAggregationQuery(com.enonic.xp.query.aggregation.NumericRangeAggregationQuery) TermsAggregationQuery(com.enonic.xp.query.aggregation.TermsAggregationQuery) ValueCountAggregationQuery(com.enonic.xp.query.aggregation.metric.ValueCountAggregationQuery) DateHistogramAggregationQuery(com.enonic.xp.query.aggregation.DateHistogramAggregationQuery) MaxAggregationQuery(com.enonic.xp.query.aggregation.metric.MaxAggregationQuery) DateRangeAggregationQuery(com.enonic.xp.query.aggregation.DateRangeAggregationQuery) AggregationQuery(com.enonic.xp.query.aggregation.AggregationQuery) GeoDistanceAggregationQuery(com.enonic.xp.query.aggregation.GeoDistanceAggregationQuery) StatsAggregationQuery(com.enonic.xp.query.aggregation.metric.StatsAggregationQuery) AggregationQueries(com.enonic.xp.query.aggregation.AggregationQueries)

Example 2 with AggregationQuery

use of com.enonic.xp.query.aggregation.AggregationQuery 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;
}
Also used : AbstractRangeAggregationQuery(com.enonic.xp.query.aggregation.AbstractRangeAggregationQuery) AbstractHistogramAggregationQuery(com.enonic.xp.query.aggregation.AbstractHistogramAggregationQuery) MetricAggregationQuery(com.enonic.xp.query.aggregation.MetricAggregationQuery) TermsAggregationQuery(com.enonic.xp.query.aggregation.TermsAggregationQuery) BucketAggregationQuery(com.enonic.xp.query.aggregation.BucketAggregationQuery) AggregationQuery(com.enonic.xp.query.aggregation.AggregationQuery) MetricAggregationQuery(com.enonic.xp.query.aggregation.MetricAggregationQuery) AbstractAggregationBuilder(org.elasticsearch.search.aggregations.AbstractAggregationBuilder) TermsAggregationQuery(com.enonic.xp.query.aggregation.TermsAggregationQuery) AbstractRangeAggregationQuery(com.enonic.xp.query.aggregation.AbstractRangeAggregationQuery) AbstractHistogramAggregationQuery(com.enonic.xp.query.aggregation.AbstractHistogramAggregationQuery) HashSet(java.util.HashSet)

Example 3 with AggregationQuery

use of com.enonic.xp.query.aggregation.AggregationQuery in project xp by enonic.

the class QueryAggregationParams method getAggregations.

public Set<AggregationQuery> getAggregations(final Map<String, Object> aggregationsMap) {
    if (aggregationsMap == null) {
        return Collections.emptySet();
    }
    final Set<AggregationQuery> aggregations = new HashSet<>();
    aggregationsMap.forEach((name, aggregationQueryMap) -> {
        final AggregationQuery aggregationQuery = aggregationQueryFromParams(name, (Map<String, Object>) aggregationQueryMap);
        if (aggregationQuery != null) {
            aggregations.add(aggregationQuery);
        }
    });
    return aggregations;
}
Also used : BucketAggregationQuery(com.enonic.xp.query.aggregation.BucketAggregationQuery) MinAggregationQuery(com.enonic.xp.query.aggregation.metric.MinAggregationQuery) HistogramAggregationQuery(com.enonic.xp.query.aggregation.HistogramAggregationQuery) NumericRangeAggregationQuery(com.enonic.xp.query.aggregation.NumericRangeAggregationQuery) TermsAggregationQuery(com.enonic.xp.query.aggregation.TermsAggregationQuery) ValueCountAggregationQuery(com.enonic.xp.query.aggregation.metric.ValueCountAggregationQuery) DateHistogramAggregationQuery(com.enonic.xp.query.aggregation.DateHistogramAggregationQuery) MaxAggregationQuery(com.enonic.xp.query.aggregation.metric.MaxAggregationQuery) DateRangeAggregationQuery(com.enonic.xp.query.aggregation.DateRangeAggregationQuery) AggregationQuery(com.enonic.xp.query.aggregation.AggregationQuery) GeoDistanceAggregationQuery(com.enonic.xp.query.aggregation.GeoDistanceAggregationQuery) StatsAggregationQuery(com.enonic.xp.query.aggregation.metric.StatsAggregationQuery) HashSet(java.util.HashSet)

Example 4 with AggregationQuery

use of com.enonic.xp.query.aggregation.AggregationQuery in project xp by enonic.

the class QueryContentHandler method doExecute.

@Override
protected Object doExecute() {
    final int start = valueOrDefault(this.start, 0);
    final int count = valueOrDefault(this.count, GetChildContentHandler.DEFAULT_COUNT);
    final ContentTypeNames contentTypeNames = getContentTypeNames();
    final QueryExpr queryExpr = QueryExpr.from(buildConstraintExpr(), buildOrderExpr());
    final Filters filters = JsonToFilterMapper.create(this.filters);
    final Set<AggregationQuery> aggregations = new QueryAggregationParams().getAggregations(this.aggregations);
    final HighlightQuery highlight = new QueryHighlightParams().getHighlightQuery(this.highlight);
    final ContentQuery.Builder queryBuilder = ContentQuery.create().from(start).size(count).aggregationQueries(aggregations).highlight(highlight).addContentTypeNames(contentTypeNames).queryExpr(queryExpr);
    for (final Filter filter : filters) {
        queryBuilder.queryFilter(filter);
    }
    final FindContentIdsByQueryResult queryResult = contentService.find(queryBuilder.build());
    return convert(queryResult);
}
Also used : AggregationQuery(com.enonic.xp.query.aggregation.AggregationQuery) FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) QueryExpr(com.enonic.xp.query.expr.QueryExpr) Filters(com.enonic.xp.query.filter.Filters) ContentQuery(com.enonic.xp.content.ContentQuery) Filter(com.enonic.xp.query.filter.Filter) ContentTypeNames(com.enonic.xp.schema.content.ContentTypeNames) HighlightQuery(com.enonic.xp.query.highlight.HighlightQuery)

Aggregations

AggregationQuery (com.enonic.xp.query.aggregation.AggregationQuery)4 BucketAggregationQuery (com.enonic.xp.query.aggregation.BucketAggregationQuery)3 TermsAggregationQuery (com.enonic.xp.query.aggregation.TermsAggregationQuery)3 DateHistogramAggregationQuery (com.enonic.xp.query.aggregation.DateHistogramAggregationQuery)2 DateRangeAggregationQuery (com.enonic.xp.query.aggregation.DateRangeAggregationQuery)2 GeoDistanceAggregationQuery (com.enonic.xp.query.aggregation.GeoDistanceAggregationQuery)2 HistogramAggregationQuery (com.enonic.xp.query.aggregation.HistogramAggregationQuery)2 NumericRangeAggregationQuery (com.enonic.xp.query.aggregation.NumericRangeAggregationQuery)2 MaxAggregationQuery (com.enonic.xp.query.aggregation.metric.MaxAggregationQuery)2 MinAggregationQuery (com.enonic.xp.query.aggregation.metric.MinAggregationQuery)2 StatsAggregationQuery (com.enonic.xp.query.aggregation.metric.StatsAggregationQuery)2 ValueCountAggregationQuery (com.enonic.xp.query.aggregation.metric.ValueCountAggregationQuery)2 HashSet (java.util.HashSet)2 ContentQuery (com.enonic.xp.content.ContentQuery)1 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)1 AbstractHistogramAggregationQuery (com.enonic.xp.query.aggregation.AbstractHistogramAggregationQuery)1 AbstractRangeAggregationQuery (com.enonic.xp.query.aggregation.AbstractRangeAggregationQuery)1 AggregationQueries (com.enonic.xp.query.aggregation.AggregationQueries)1 MetricAggregationQuery (com.enonic.xp.query.aggregation.MetricAggregationQuery)1 QueryExpr (com.enonic.xp.query.expr.QueryExpr)1