Skip to content

Commit

Permalink
fix facets for year published
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Sep 13, 2020
1 parent 8561af4 commit a9056c5
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
8 changes: 6 additions & 2 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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"] }
Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/event_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/image_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/software_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a9056c5

Please sign in to comment.