From 2d51179c2ae0cdf0df16071f43dc5baed6e651ee Mon Sep 17 00:00:00 2001 From: Kristian Garza Date: Fri, 2 Aug 2019 19:22:52 +0200 Subject: [PATCH] fix facet --- app/controllers/concerns/facetable.rb | 14 ++++++++++++++ app/controllers/events_controller.rb | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index 62c42372d..731b29d12 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -148,6 +148,20 @@ def facet_citations_by_year(hash) "years" => arr } end + def facet_citations_by_year_v1(hash) + arr = hash.dig('years', 'buckets').map do |h| + year = h["key_as_string"][0..3].to_i + title = h["key_as_string"][0..3] + + { + 'id' => year, + 'title' => title, + 'sum' => h.dig('total_by_year', 'value') } + end + { "count" => hash.dig("sum_distribution", "value"), + "years" => arr } + end + def facet_counts_by_year_month(hash) arr = hash.dig('year_months', 'buckets').map do |h| month = h["key_as_string"][5..6].to_i diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 879c54b11..6a5190db2 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -125,7 +125,7 @@ def index pairings = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_pairings(response.response.aggregations.pairings.buckets) : nil dois = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_dois(response.response.aggregations.dois.buckets) : nil dois_usage = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_dois(response.response.aggregations.dois_usage.dois.buckets) : nil - dois_citations = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_citations_by_year(response.response.aggregations.dois_citations) : nil + dois_citations = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_citations_by_year_v1(response.response.aggregations.dois_citations) : nil citations_histogram = total.positive? && aggregations.include?("metrics_aggregations") ? facet_citations_by_year(response.response.aggregations.citations_histogram) : nil citations = total.positive? && aggregations.include?("metrics_aggregations") ? facet_citations_by_dois(response.response.aggregations.citations.dois.buckets) : nil views_histogram = total.positive? && aggregations.include?("metrics_aggregations") ? facet_counts_by_year_month(response.response.aggregations.views_histogram) : nil