diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index e2d3c9b4d..a3717e7ad 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -55,6 +55,8 @@ module Facetable "ogl-canada-2.0" => "OGL-Canada-2.0" } + LOWER_BOUND_YEAR = 2010 + included do def facet_by_key_as_string(arr) arr.map do |hsh| @@ -72,9 +74,11 @@ def facet_by_year(arr) end end - # remove years in the future and only keep 10 most recent years + # remove years in the future and only keep 12 most recent years def facet_by_range(arr) - arr.select { |a| a["key_as_string"].to_i <= 2020 }[0..9].map do |hsh| + interval = Date.current.year - LOWER_BOUND_YEAR + + arr.select { |a| a["key_as_string"].to_i <= Date.current.year }[0..interval].map do |hsh| { "id" => hsh["key_as_string"], "title" => hsh["key_as_string"], "count" => hsh["doc_count"] } diff --git a/app/graphql/types/base_connection.rb b/app/graphql/types/base_connection.rb index aecfdc0bc..717b794f9 100644 --- a/app/graphql/types/base_connection.rb +++ b/app/graphql/types/base_connection.rb @@ -143,9 +143,9 @@ def facet_by_registration_agency(arr) # remove years in the future and only keep 12 most recent years def facet_by_range(arr) - interval = Date.current.year - LOWER_BOUND_YEAR + 1 + interval = Date.current.year - LOWER_BOUND_YEAR - arr.select { |a| a["key_as_string"].to_i <= 2020 }[0..interval].map do |hsh| + arr.select { |a| a["key_as_string"].to_i <= Date.current.year }[0..interval].map do |hsh| { "id" => hsh["key_as_string"], "title" => hsh["key_as_string"], "count" => hsh["doc_count"] } diff --git a/app/graphql/types/event_connection_with_total_type.rb b/app/graphql/types/event_connection_with_total_type.rb index eb342190d..1cfeefe93 100644 --- a/app/graphql/types/event_connection_with_total_type.rb +++ b/app/graphql/types/event_connection_with_total_type.rb @@ -17,7 +17,7 @@ def total_count end def published - facet_by_year(object.aggregations.published.buckets) + facet_by_range(object.aggregations.published.buckets) end def registration_agencies diff --git a/app/graphql/types/image_connection_with_total_type.rb b/app/graphql/types/image_connection_with_total_type.rb index 1e6b4d7bf..a46169e91 100644 --- a/app/graphql/types/image_connection_with_total_type.rb +++ b/app/graphql/types/image_connection_with_total_type.rb @@ -17,7 +17,7 @@ def total_count end def published - facet_by_year(object.aggregations.published.buckets) + facet_by_range(object.aggregations.published.buckets) end def registration_agencies diff --git a/app/graphql/types/publication_connection_with_total_type.rb b/app/graphql/types/publication_connection_with_total_type.rb index 04a285747..ba96e5771 100644 --- a/app/graphql/types/publication_connection_with_total_type.rb +++ b/app/graphql/types/publication_connection_with_total_type.rb @@ -25,7 +25,7 @@ def total_count end def published - facet_by_year(object.aggregations.published.buckets) + facet_by_range(object.aggregations.published.buckets) end def registration_agencies diff --git a/app/graphql/types/software_connection_with_total_type.rb b/app/graphql/types/software_connection_with_total_type.rb index b7e3bc6c7..d5b0cc25d 100644 --- a/app/graphql/types/software_connection_with_total_type.rb +++ b/app/graphql/types/software_connection_with_total_type.rb @@ -25,7 +25,7 @@ def total_count end def published - facet_by_year(object.aggregations.published.buckets) + facet_by_range(object.aggregations.published.buckets) end def registration_agencies