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