Skip to content

Commit

Permalink
Merge pull request #953 from datacite/doi-enrichment-graphql
Browse files Browse the repository at this point in the history
doi enrichment graphql
  • Loading branch information
jrhoads authored Apr 13, 2023
2 parents 4816921 + 0b3a2ab commit 6bf7b28
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
4 changes: 4 additions & 0 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ def actor(id:)
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :field_of_science, String, required: false
argument :field_of_science_repository, String, required: false
argument :field_of_science_combined, String, required: false
argument :facet_count, Int, required: false, default_value: 10
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
Expand Down Expand Up @@ -1281,6 +1283,8 @@ def response(**args)
has_views: args[:has_views],
has_downloads: args[:has_downloads],
field_of_science: args[:field_of_science],
field_of_science_repository: args[:field_of_science_repository],
field_of_science_combined: args[:field_of_science_combined],
facet_count: args[:facet_count],
pid_entity: args[:pid_entity],
state: "findable",
Expand Down
18 changes: 18 additions & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,12 @@ def self.gql_query_aggregations(facet_count: 10)
include: "FOS:.*" } },
},
},
fields_of_science_combined: {
terms: { field: "fields_of_science_combined", size: facet_count, min_doc_count: 1 }
},
fields_of_science_repository: {
terms: { field: "fields_of_science_repository", size: facet_count, min_doc_count: 1 }
},
licenses: { terms: { field: "rights_list.rightsIdentifier", size: facet_count, min_doc_count: 1 } },
languages: { terms: { field: "language", size: facet_count, min_doc_count: 1 } },
view_count: { sum: { field: "view_count" } },
Expand Down Expand Up @@ -929,6 +935,12 @@ def self.gql_query(query, options = {})
filter << { term: { "subjects.subjectScheme": "Fields of Science and Technology (FOS)" } }
filter << { terms: { "subjects.subject": options[:field_of_science].split(",").map { |s| "FOS: " + s.humanize } } }
end
if options[:field_of_science_repository].present?
filter << { terms: { "fields_of_science_repository": options[:field_of_science_repository].split(",").map { |s| s.humanize } } }
end
if options[:field_of_science_combined].present?
filter << { terms: { "fields_of_science_combined": options[:field_of_science_combined].split(",").map { |s| s.humanize } } }
end
filter << { terms: { "rights_list.rightsIdentifier" => options[:license].split(",") } } if options[:license].present?
filter << { term: { source: options[:source] } } if options[:source].present?
filter << { range: { reference_count: { "gte": options[:has_references].to_i } } } if options[:has_references].present?
Expand Down Expand Up @@ -1131,6 +1143,12 @@ def self.query(query, options = {})
filter << { term: { "subjects.subjectScheme": "Fields of Science and Technology (FOS)" } }
filter << { terms: { "subjects.subject": options[:field_of_science].split(",").map { |s| "FOS: " + s.humanize } } }
end
if options[:field_of_science_repository].present?
filter << { terms: { "fields_of_science_repository": options[:field_of_science_repository].split(",").map { |s| s.humanize } } }
end
if options[:field_of_science_combined].present?
filter << { terms: { "fields_of_science_combined": options[:field_of_science_combined].split(",").map { |s| s.humanize } } }
end
filter << { terms: { "rights_list.rightsIdentifier" => options[:license].split(",") } } if options[:license].present?
filter << { term: { source: options[:source] } } if options[:source].present?
filter << { range: { reference_count: { "gte": options[:has_references].to_i } } } if options[:has_references].present?
Expand Down
27 changes: 13 additions & 14 deletions spec/graphql/types/work_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1270,19 +1270,18 @@
).to match_array([])
end

# Temporariliy disable these tests until gql/aggregates are enabled
# it "returns Field of Science Facets from the repository" do
# response = @facet_response
# expect(
# response.dig("data", "works", "fieldsOfScienceRepository")
# ).to match_array([ fos_facet ])
# end

# it "returns combined Field of Science Facets" do
# response = @facet_response
# expect(
# response.dig("data", "works", "fieldsOfScienceCombined")
# ).to match_array([ fos_facet ])
# end
it "returns Field of Science Facets from the repository" do
response = @facet_response
expect(
response.dig("data", "works", "fieldsOfScienceRepository")
).to match_array([ fos_facet ])
end

it "returns combined Field of Science Facets" do
response = @facet_response
expect(
response.dig("data", "works", "fieldsOfScienceCombined")
).to match_array([ fos_facet ])
end
end
end

0 comments on commit 6bf7b28

Please sign in to comment.