diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 72dc8d148..8be527afb 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -131,7 +131,7 @@ def destroy def totals page = { size: 0, number: 1} - response = Doi.query(nil, provider_id: params[:provider_id], page: page) + response = Doi.query(nil, provider_id: params[:provider_id], page: page, totals_agg: true) total = response.results.total registrant = total > 0 ? clients_totals(response.response.aggregations.clients_totals.buckets) : nil diff --git a/app/controllers/prefixes_controller.rb b/app/controllers/prefixes_controller.rb index 57a662cc8..cc1a241c4 100644 --- a/app/controllers/prefixes_controller.rb +++ b/app/controllers/prefixes_controller.rb @@ -138,7 +138,7 @@ def update def totals page = { size: 0, number: 1} - response = Doi.query("", client_id: params[:client_id],page: page) + response = Doi.query("", client_id: params[:client_id],page: page, totals_agg: true) total = response.results.total registrant = total > 0 ? prefixes_totals(response.response.aggregations.prefixes_totals.buckets) : nil diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index c34cdea54..c8d5bfa95 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -122,7 +122,9 @@ def update def totals page = { size: 0, number: 1} - response = Doi.query("", page: page) + + response = Doi.query("", page: page, totals_agg: true) + total = response.results.total registrant = total > 0 ? providers_totals(response.response.aggregations.providers_totals.buckets) : nil diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index d404ecc23..29b2b97b4 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -100,7 +100,7 @@ def find_by_ids(ids, options={}) end def query(query, options={}) - aggregations = query_aggregations + aggregations = options[:totals_agg] == true ? totals_aggregations : query_aggregations options[:page] ||= { size: 25, number: 1 } # enable cursor-based pagination for DOIs diff --git a/app/models/doi.rb b/app/models/doi.rb index 5bea93851..8f5b35faa 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -326,10 +326,15 @@ def self.query_aggregations link_checks_citation_doi: { value_count: { field: "landing_page.citationDoi" } }, links_checked: { value_count: { field: "landing_page.checked" } }, sources: { terms: { field: 'source', size: 15, min_doc_count: 1 } }, - providers_totals: { terms: { field: 'provider_id', size: 500, min_doc_count: 1 }, aggs: sub_aggregations}, + subjects: { terms: { field: 'subjects.subject', size: 15, min_doc_count: 1 } } + } + end + + def self.totals_aggregations + { + providers_totals: { terms: { field: 'provider_id', size: 200, min_doc_count: 1 }, aggs: sub_aggregations}, clients_totals: { terms: { field: 'client_id', size: 2000, min_doc_count: 1 }, aggs: sub_aggregations }, prefixes_totals: { terms: { field: 'prefix', size: 2000, min_doc_count: 1 }, aggs: sub_aggregations }, - subjects: { terms: { field: 'subjects.subject', size: 15, min_doc_count: 1 } } } end @@ -339,7 +344,7 @@ def self.sub_aggregations beginning_of_month = DateTime.current.beginning_of_month.strftime('%Y-%m-%d') { - states: { terms: { field: 'aasm_state', size: 15, min_doc_count: 1 } }, + states: { terms: { field: 'aasm_state', size: 4, min_doc_count: 1 } }, this_month:{ date_range:{ field: 'created', time_zone: "CET", ranges: {from: beginning_of_month, to: "now/d"} } }, this_year: { date_range: { field: 'created', time_zone: "CET", ranges: {from: beginning_of_year, to: "now/d"} } }, last_year: { date_range: { field: 'created', time_zone: "CET", ranges: {from: beginning_of_last_year, to: beginning_of_year} } }