Skip to content

Commit

Permalink
facet by year range starts in 2010
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Sep 13, 2020
1 parent 5cf464d commit 8561af4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/graphql/types/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class BaseConnection < GraphQL::Types::Relay::BaseConnection
"mpl-2.0" => "MPL-2.0",
"ogl-canada-2.0" => "OGL-Canada-2.0"
}

LOWER_BOUND_YEAR = 2010

def doi_from_url(url)
if /\A(?:(http|https):\/\/(dx\.)?(doi.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match?(url)
Expand Down Expand Up @@ -139,9 +141,11 @@ def facet_by_registration_agency(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 + 1

arr.select { |a| a["key_as_string"].to_i <= 2020 }[0..interval].map do |hsh|
{ "id" => hsh["key_as_string"],
"title" => hsh["key_as_string"],
"count" => hsh["doc_count"] }
Expand Down

0 comments on commit 8561af4

Please sign in to comment.