From 6efac480999e855ee530fe4be68ef895bae9643f Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Thu, 1 Jul 2021 08:59:24 +0200 Subject: [PATCH 1/2] Add a new aggregation to support open_licenses This aggregation will remove need to count manually licenses on frontend. In addition this also will give sub aggregation that counts by resourcetype. --- .../types/work_connection_with_total_type.rb | 18 ++++++++++++++++-- app/models/doi.rb | 8 ++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/graphql/types/work_connection_with_total_type.rb b/app/graphql/types/work_connection_with_total_type.rb index 1241c465f..1aebf9b98 100644 --- a/app/graphql/types/work_connection_with_total_type.rb +++ b/app/graphql/types/work_connection_with_total_type.rb @@ -7,9 +7,11 @@ class WorkConnectionWithTotalType < BaseConnection field :total_count, Integer, null: false, cache: true field :totalCountFromCrossref, resolver: TotalCountFromCrossref, null: true, cache: true + field :total_open_licenses, Integer, null: true, cache: true field :total_content_url, Integer, null: true, cache: true field :published, [FacetType], null: true, cache: true field :resource_types, [FacetType], null: true, cache: true + field :open_license_resource_types, [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 @@ -26,6 +28,10 @@ def total_content_url object.aggregations.content_url_count.value.to_i end + def total_open_licenses + object.aggregations.open_licenses.doc_count.to_i + end + def published if object.aggregations.published facet_by_range(object.aggregations.published.buckets) @@ -35,8 +41,16 @@ def published end def resource_types - if object.aggregations.resource_types - facet_by_combined_key(object.aggregations.resource_types.buckets) + if object.aggregations.authors + facet_by_combined_key(object.aggregations.authors.buckets) + else + [] + end + end + + def open_license_resource_types + if object.aggregations.open_licenses + facet_by_combined_key(object.aggregations.open_licenses.resource_types.buckets) else [] end diff --git a/app/models/doi.rb b/app/models/doi.rb index 4613509d7..023dd6eb0 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -588,6 +588,14 @@ def self.gql_query_aggregations(facet_count: 10) if facet_count.positive? { resource_types: { terms: { field: "resource_type_id_and_name", size: facet_count, min_doc_count: 1 } }, + open_licenses: { + filter: { terms: { "rights_list.rightsIdentifier": ["cc-by-1.0", "cc-by-2.0", "cc-by-2.5", "cc-by-3.0", "cc-by-3.0-at", "cc-by-3.0-us", "cc-by-4.0", "cc-pddc", "cc0-1.0", "cc-pdm-1.0"] } }, + aggs: { + resource_types: { + terms: { field: "resource_type_id_and_name", size: facet_count, min_doc_count: 1 } + } + } + }, published: { date_histogram: { field: "publication_year", From beb100e935f32a3b77b7a6e9aa8205fa2f42ca2b Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Thu, 1 Jul 2021 09:14:56 +0200 Subject: [PATCH 2/2] Fix - Accidental switch of resource_types aggregation --- app/graphql/types/work_connection_with_total_type.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/graphql/types/work_connection_with_total_type.rb b/app/graphql/types/work_connection_with_total_type.rb index 1aebf9b98..c8902a8de 100644 --- a/app/graphql/types/work_connection_with_total_type.rb +++ b/app/graphql/types/work_connection_with_total_type.rb @@ -42,7 +42,7 @@ def published def resource_types if object.aggregations.authors - facet_by_combined_key(object.aggregations.authors.buckets) + facet_by_combined_key(object.aggregations.resource_types.buckets) else [] end