def _get_aggregated_query(self, start, limit): max_size = (start or 0) + (limit or 0) query = HQESQuery(self.table_name).size(0) for filter in self.filters: query = query.filter(filter) innermost_agg_col = self.aggregation_columns[-1] innermost_agg = TermsAggregation(innermost_agg_col, innermost_agg_col, size=max_size) aggregations = [] for col in self.top_level_columns: for agg in col.aggregations(self.config, self.lang): innermost_agg.aggregation(agg) top_agg = innermost_agg # go through aggregations in reverse order so that they are nested properly # todo: Refactor NestedTermAggregationsHelper to support this use case for agg_column in self.aggregation_columns[:-1][::-1]: top_agg = TermsAggregation(agg_column, agg_column, size=max_size).aggregation(top_agg) if self.order_by: # todo sort by more than one column # todo sort by by something other than the first aggregate column col, desc = self.order_by[0] if col == self.aggregation_columns[ 0] or col == self.top_level_columns[0].field: top_agg = top_agg.order('_term', desc) query = query.aggregation(top_agg) return query.run()
def _get_aggregated_query(self, start, limit): max_size = (start or 0) + (limit or 0) query = HQESQuery(self.table_name).size(0) for filter in self.filters: query = query.filter(filter) innermost_agg_col = self.aggregation_columns[-1] innermost_agg = TermsAggregation(innermost_agg_col, innermost_agg_col, size=max_size) aggregations = [] for col in self.top_level_columns: for agg in col.aggregations(self.config, self.lang): innermost_agg.aggregation(agg) top_agg = innermost_agg # go through aggregations in reverse order so that they are nested properly for agg_column in self.aggregation_columns[:-1][::-1]: top_agg = TermsAggregation(agg_column, agg_column, size=max_size).aggregation(top_agg) if self.order_by: col, desc = self.order_by[0] valid_columns = ( self.aggregation_columns[0], self.top_level_columns[0].field, self.top_level_columns[0].column_id ) if col in valid_columns: top_agg = top_agg.order('_term', desc) query = query.aggregation(top_agg) return query.run()
def _get_aggregated_query(self, start, limit): max_size = (start or 0) + (limit or 0) query = HQESQuery(self.table_name).size(0) for filter in self.filters: query = query.filter(filter) innermost_agg_col = self.aggregation_columns[-1] innermost_agg = TermsAggregation(innermost_agg_col, innermost_agg_col) aggregations = [] for col in self.top_level_columns: for agg in col.aggregations(self.config, self.lang): innermost_agg.aggregation(agg) top_agg = innermost_agg # go through aggregations in reverse order so that they are nested properly # todo: Refactor NestedTermAggregationsHelper to support this use case for agg_column in self.aggregation_columns[:-1][::-1]: top_agg = TermsAggregation(agg_column, agg_column).aggregation(top_agg) top_agg.size(max_size) if self.order_by: # todo sort by more than one column # todo sort by by something other than the first aggregate column col, desc = self.order_by[0] if col == self.aggregation_columns[0] or col == self.top_level_columns[0].field: top_agg = top_agg.order('_term', desc) query = query.aggregation(top_agg) return query.run()
def _get_aggregated_query(self, start, limit): max_size = (start or 0) + (limit or 0) query = HQESQuery(self.table_name).size(0) for filter in self.filters: query = query.filter(filter) top_agg = TermsAggregation(self.aggregation_columns[0], self.aggregation_columns[0], size=max_size) for agg_column in self.aggregation_columns[1:]: # todo support multiple aggregations pass aggregations = [] for col in self.top_level_columns: if col.type == 'expanded': for sub_col in get_expanded_column_config( self.config, col, 'en').columns: aggregations.append(sub_col.aggregation) elif col.type == 'field': if col.aggregation == 'sum': # todo push this to the column aggregations.append(SumAggregation(col.field, col.field)) for agg in aggregations: top_agg = top_agg.aggregation(agg) if self.order_by: # todo sort by more than one column # todo sort by by something other than the first aggregate column col, desc = self.order_by[0] if col == self.aggregation_columns[ 0] or col == self.top_level_columns[0].field: top_agg = top_agg.order('_count', desc) query = query.aggregation(top_agg) return query.run()