Skip to content

Commit

Permalink
Merge branch 'master' of github.com:datacite/lupo
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhallett committed Mar 19, 2019
2 parents 2280eff + 827e099 commit 0f3c9c9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/prefixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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} } }
Expand Down

0 comments on commit 0f3c9c9

Please sign in to comment.