From 502a4a1896700d3bbfcbbebf54c03a95b763b8db Mon Sep 17 00:00:00 2001 From: jrhoads Date: Wed, 12 Apr 2023 15:40:44 -0400 Subject: [PATCH 1/2] Allow FOS facets and filtering for repositories and combined FOS feilds --- app/models/doi.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/models/doi.rb b/app/models/doi.rb index b0ccd9357..53534e891 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -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" } }, @@ -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? @@ -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? From 0b3a2aba12c5df45c8312ea6fdf3662fa5d0a51e Mon Sep 17 00:00:00 2001 From: jrhoads Date: Wed, 12 Apr 2023 15:41:33 -0400 Subject: [PATCH 2/2] Expose FOS facets and filtering in Graphql --- app/graphql/types/query_type.rb | 4 ++++ spec/graphql/types/work_type_spec.rb | 27 +++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 3fe3124b7..8e88ec927 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -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 @@ -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", diff --git a/spec/graphql/types/work_type_spec.rb b/spec/graphql/types/work_type_spec.rb index 296b809db..6f5473628 100644 --- a/spec/graphql/types/work_type_spec.rb +++ b/spec/graphql/types/work_type_spec.rb @@ -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