Class: ElasticGraph::GraphQL::Aggregation::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/graphql/aggregation/query.rb

Instance Method Summary collapse

Instance Method Details

#build_agg_detail(filter_interpreter, field_path:, parent_queries:) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/elastic_graph/graphql/aggregation/query.rb', line 60

def build_agg_detail(filter_interpreter, field_path:, parent_queries:)
  return nil if paginator.desired_page_size.zero? || paginator.paginated_from_singleton_cursor?
  queries = parent_queries + [self] # : ::Array[Query]

  filter_detail(filter_interpreter, field_path) do
    grouping_adapter.grouping_detail_for(self) do
      Support::HashUtil.disjoint_merge(computations_detail, sub_aggregation_detail(filter_interpreter, queries))
    end
  end
end

#build_agg_hash(filter_interpreter) ⇒ Object

Builds an aggregations hash. The returned value has a few different cases:

  • If size is 0, or groupings and computations are both empty, we return an empty hash, so that to_datastore_body is an empty hash. We do this so that we avoid sending the datastore any sort of aggregations query in these cases, as the client is not requesting any aggregation data.

  • If SINGLETON_CURSOR was provide for either before or after, we also return an empty hash, because we know there cannot be any results to return–the cursor is a reference to the one and only item in the list, and nothing can exist before or after it.

  • Otherwise, we return an aggregatinos hash based on the groupings, computations, and sub-aggregations.



56
57
58
# File 'lib/elastic_graph/graphql/aggregation/query.rb', line 56

def build_agg_hash(filter_interpreter)
  build_agg_detail(filter_interpreter, field_path: [], parent_queries: [])&.clauses || {}
end

#needs_total_doc_count?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
# File 'lib/elastic_graph/graphql/aggregation/query.rb', line 38

def needs_total_doc_count?
  # We only need a total document count when there are NO groupings and the doc count is requested.
  # The datastore will return the number of hits in each grouping automatically, so we don't need
  # a total doc count when there are groupings. And when the query isn't requesting the field, we
  # don't need it, either.
  needs_doc_count && groupings.empty?
end