Skip to content

Commit

Permalink
allow faceting by publication_year
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 5, 2020
1 parent 658f222 commit 2be12c0
Show file tree
Hide file tree
Showing 45 changed files with 205 additions and 127 deletions.
6 changes: 4 additions & 2 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def index
response = Doi.query(params[:query],
state: params[:state],
exclude_registration_agencies: params[:exclude_registration_agencies],
published: params[:published],
created: params[:created],
registered: params[:registered],
provider_id: params[:provider_id],
Expand Down Expand Up @@ -155,7 +156,7 @@ def index
else
states = total.positive? ? facet_by_key(response.aggregations.states.buckets) : nil
resource_types = total.positive? ? facet_by_combined_key(response.aggregations.resource_types.buckets) : nil
years = total.positive? ? facet_by_range(response.aggregations.years.buckets) : nil
published = total.positive? ? facet_by_range(response.aggregations.published.buckets) : nil
created = total.positive? ? facet_by_key_as_string(response.aggregations.created.buckets) : nil
registered = total.positive? ? facet_by_key_as_string(response.aggregations.registered.buckets) : nil
providers = total.positive? ? facet_by_combined_key(response.aggregations.providers.buckets) : nil
Expand Down Expand Up @@ -190,7 +191,7 @@ def index
states: states,
"resourceTypes" => resource_types,
created: created,
published: years,
published: published,
registered: registered,
providers: providers,
clients: clients,
Expand Down Expand Up @@ -225,6 +226,7 @@ def index
"resource-type-id" => params[:resource_type_id],
prefix: params[:prefix],
certificate: params[:certificate],
published: params[:published],
created: params[:created],
registered: params[:registered],
"has-citations" => params[:has_citations],
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/audiovisual_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AudiovisualConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -14,8 +14,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_range(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? facet_by_range(object.aggregations.published.buckets) : []
end

def registration_agencies
Expand Down
13 changes: 5 additions & 8 deletions app/graphql/types/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,12 @@ def facet_by_fos(arr)
end
end

# remove years in the future and only keep 10 most recent years
def facet_by_range(arr)
arr.reduce([]) do |sum, hsh|
if hsh["doc_count"] > 0
sum << { "id" => hsh["from_as_string"],
"title" => hsh["from_as_string"],
"count" => hsh["doc_count"] }
end

sum
arr.select { |a| a["key_as_string"].to_i <= 2020 }[0..9].map do |hsh|
{ "id" => hsh["key_as_string"],
"title" => hsh["key_as_string"],
"count" => hsh["doc_count"] }
end
end
end
6 changes: 3 additions & 3 deletions app/graphql/types/book_chapter_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class BookChapterConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -14,8 +14,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_range(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? facet_by_range(object.aggregations.published.buckets) : []
end

def registration_agencies
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/book_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class BookConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -14,8 +14,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_range(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? facet_by_range(object.aggregations.published.buckets) : []
end

def registration_agencies
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/collection_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ class CollectionConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true

def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_range(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? 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 @@ -5,7 +5,7 @@ class ConferencePaperConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -15,8 +15,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_range(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? facet_by_range(object.aggregations.published.buckets) : []
end

def registration_agencies
Expand Down
3 changes: 2 additions & 1 deletion app/graphql/types/data_catalog_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DataCatalogType < BaseObject
field :datasets, DatasetConnectionWithTotalType, null: true, description: "Funded datasets" do
argument :query, String, required: false
argument :user_id, String, required: false
argument :published, String, required: false
argument :repository_id, String, required: false
argument :member_id, String, required: false
argument :has_citations, Int, required: false
Expand Down Expand Up @@ -77,7 +78,7 @@ def software_application
end

def datasets(**args)
Doi.query(args[:query], re3data_id: object[:id], user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], resource_type_id: "Dataset", state: "findable", page: { cursor: args[:cursor].present? ? Base64.urlsafe_decode64(args[:cursor]) : nil, size: args[:size] })
Doi.query(args[:query], re3data_id: object[:id], user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], resource_type_id: "Dataset", published: args[:published], state: "findable", page: { cursor: args[:cursor].present? ? Base64.urlsafe_decode64(args[:cursor]) : nil, size: args[:size] })
end

def view_count
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/data_paper_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DataPaperConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -14,8 +14,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_range(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? facet_by_range(object.aggregations.published.buckets) : []
end

def registration_agencies
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/dataset_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DatasetConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -22,8 +22,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_range(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? facet_by_range(object.aggregations.published.buckets) : []
end

def registration_agencies
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/dissertation_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DissertationConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -15,8 +15,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_range(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? facet_by_range(object.aggregations.published.buckets) : []
end

def registration_agencies
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/event_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class EventConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -14,8 +14,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_year(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? facet_by_year(object.aggregations.published.buckets) : []
end

def registration_agencies
Expand Down
6 changes: 5 additions & 1 deletion app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class FunderType < BaseObject
field :datasets, DatasetConnectionWithTotalType, null: true, description: "Funded datasets" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :published, String, required: false
argument :user_id, String, required: false
argument :repository_id, String, required: false
argument :member_id, String, required: false
Expand All @@ -31,6 +32,7 @@ class FunderType < BaseObject
field :publications, PublicationConnectionWithTotalType, null: true, description: "Funded publications" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :published, String, required: false
argument :user_id, String, required: false
argument :repository_id, String, required: false
argument :member_id, String, required: false
Expand All @@ -49,6 +51,7 @@ class FunderType < BaseObject
field :softwares, SoftwareConnectionWithTotalType, null: true, description: "Funded software" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :published, String, required: false
argument :user_id, String, required: false
argument :repository_id, String, required: false
argument :member_id, String, required: false
Expand All @@ -67,6 +70,7 @@ class FunderType < BaseObject
field :works, WorkConnectionWithTotalType, null: true, description: "Funded works" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :published, String, required: false
argument :user_id, String, required: false
argument :repository_id, String, required: false
argument :member_id, String, required: false
Expand Down Expand Up @@ -127,6 +131,6 @@ def citation_count
end

def response(**args)
Doi.query(args[:query], ids: args[:ids], funder_id: object.id, user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], affiliation_id: args[:affiliation_id], resource_type_id: args[:resource_type_id], has_person: args[:has_person], has_organization: args[:has_organization], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], field_of_science: args[:field_of_science], state: "findable", page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : nil, size: args[:first] })
Doi.query(args[:query], ids: args[:ids], funder_id: object.id, user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], affiliation_id: args[:affiliation_id], resource_type_id: args[:resource_type_id], has_person: args[:has_person], has_organization: args[:has_organization], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], field_of_science: args[:field_of_science], published: args[:published], state: "findable", page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : nil, size: args[:first] })
end
end
6 changes: 3 additions & 3 deletions app/graphql/types/image_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ImageConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -14,8 +14,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_year(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? facet_by_year(object.aggregations.published.buckets) : []
end

def registration_agencies
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/instrument_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class InstrumentConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -14,8 +14,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_range(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? 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 @@ -5,7 +5,7 @@ class InteractiveResourceConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -14,8 +14,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_range(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? 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 @@ -5,7 +5,7 @@ class JournalArticleConnectionWithTotalType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
Expand All @@ -15,8 +15,8 @@ def total_count
object.total_count
end

def years
object.total_count.positive? ? facet_by_range(object.aggregations.years.buckets) : []
def published
object.total_count.positive? ? facet_by_range(object.aggregations.published.buckets) : []
end

def registration_agencies
Expand Down
Loading

0 comments on commit 2be12c0

Please sign in to comment.