Skip to content

Commit

Permalink
Add a new aggregation to support open_licenses
Browse files Browse the repository at this point in the history
This aggregation will remove need to count manually licenses on frontend.
In addition this also will give sub aggregation that counts by resourcetype.
  • Loading branch information
richardhallett committed Jul 1, 2021
1 parent 6dcd8f9 commit 6efac48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/graphql/types/work_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6efac48

Please sign in to comment.