Class: ElasticGraph::GraphQL::Aggregation::Query
- Inherits:
-
Object
- Object
- ElasticGraph::GraphQL::Aggregation::Query
- Defined in:
- lib/elastic_graph/graphql/aggregation/query.rb
Instance Method Summary collapse
- #build_agg_detail(filter_interpreter, field_path:, parent_queries:) ⇒ Object
-
#build_agg_hash(filter_interpreter) ⇒ Object
Builds an aggregations hash.
- #needs_total_doc_count? ⇒ Boolean
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
sizeis 0, orgroupingsandcomputationsare both empty, we return an empty hash, so thatto_datastore_bodyis 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_CURSORwas provide for eitherbeforeorafter, 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
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 |