From 6d8b8851c7d431bb5d76e70a16b49d2847dbac68 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Fri, 2 Jun 2023 09:52:53 +0200 Subject: [PATCH] Revert "Merge pull request #965 from datacite/fair-vis-feature-6" This reverts commit 6e71b5d08f751a4828f06e014a7ddd07e159f43f, reversing changes made to 2cc956e56ad57e0809b974363c0493a95c3fa9ea. --- app/controllers/concerns/facetable.rb | 19 +-- .../types/interfaces/work_facets_interface.rb | 6 +- .../types/work_connection_with_total_type.rb | 3 +- app/models/doi.rb | 6 +- spec/graphql/types/work_type_spec.rb | 131 ------------------ 5 files changed, 7 insertions(+), 158 deletions(-) diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index 904445095..ae61a55ce 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -69,7 +69,6 @@ module Facetable "mit" => "MIT", "mpl-2.0" => "MPL-2.0", "ogl-canada-2.0" => "OGL-Canada-2.0", - "__missing__" => "Missing", }.freeze LOWER_BOUND_YEAR = 2_010 @@ -80,8 +79,6 @@ module Facetable "igsnCatalog" => "IGSN ID Catalog" }.freeze - OTHER = { "__other__" => "Other", "__missing__" => "Missing" }.freeze - included do def facet_by_key_as_string(arr) arr.map do |hsh| @@ -446,9 +443,7 @@ def clients_totals(arr) def facet_by_combined_key(arr) arr.map do |hsh| id, title = hsh["key"].split(":", 2) - if id == "__missing__" - title = OTHER["__missing__"] - end + { "id" => id, "title" => title, "count" => hsh["doc_count"] } end end @@ -494,17 +489,5 @@ def facet_by_authors(arr) end }.compact end - - def add_other(arr, other_count) - if other_count > 0 - arr << { - "id" => "__other__", - "title" => OTHER["__other__"], - "count" => other_count, - } - end - - arr - end end end diff --git a/app/graphql/types/interfaces/work_facets_interface.rb b/app/graphql/types/interfaces/work_facets_interface.rb index a23893f47..5dc58c19e 100644 --- a/app/graphql/types/interfaces/work_facets_interface.rb +++ b/app/graphql/types/interfaces/work_facets_interface.rb @@ -58,8 +58,7 @@ def repositories def affiliations if object.aggregations.affiliations - arr = facet_by_combined_key(object.aggregations.affiliations.buckets) - add_other(arr, object.aggregations.affiliations.sum_other_doc_count) + facet_by_combined_key(object.aggregations.affiliations.buckets) else [] end @@ -75,8 +74,7 @@ def authors def licenses if object.aggregations.licenses - arr = facet_by_license(object.aggregations.licenses.buckets) - add_other(arr, object.aggregations.licenses.sum_other_doc_count) + facet_by_license(object.aggregations.licenses.buckets) else [] end diff --git a/app/graphql/types/work_connection_with_total_type.rb b/app/graphql/types/work_connection_with_total_type.rb index 8031842ec..ff55d6c9e 100644 --- a/app/graphql/types/work_connection_with_total_type.rb +++ b/app/graphql/types/work_connection_with_total_type.rb @@ -22,8 +22,7 @@ def total_open_licenses def resource_types if object.aggregations.resource_types - arr = facet_by_combined_key(object.aggregations.resource_types.buckets) - add_other(arr, object.aggregations.resource_types.sum_other_doc_count) + facet_by_combined_key(object.aggregations.resource_types.buckets) else [] end diff --git a/app/models/doi.rb b/app/models/doi.rb index 45d2426ed..53534e891 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -614,7 +614,7 @@ def as_indexed_json(_options = {}) 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, missing: "__missing__" } }, + resource_types: { terms: { field: "resource_type_id_and_name", size: facet_count, min_doc_count: 1 } }, clients: { terms: { field: "client_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"] } }, @@ -636,7 +636,7 @@ def self.gql_query_aggregations(facet_count: 10) }, }, registration_agencies: { terms: { field: "agency", size: facet_count, min_doc_count: 1 } }, - affiliations: { terms: { field: "affiliation_id_and_name", size: facet_count, min_doc_count: 1, missing: "__missing__" } }, + affiliations: { terms: { field: "affiliation_id_and_name", size: facet_count, min_doc_count: 1 } }, authors: { terms: { field: "creators.nameIdentifiers.nameIdentifier", size: facet_count, min_doc_count: 1 }, aggs: { @@ -670,7 +670,7 @@ def self.gql_query_aggregations(facet_count: 10) 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, missing: "__missing__" } }, + 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" } }, download_count: { sum: { field: "download_count" } }, diff --git a/spec/graphql/types/work_type_spec.rb b/spec/graphql/types/work_type_spec.rb index 3260acc2c..7499c65cf 100644 --- a/spec/graphql/types/work_type_spec.rb +++ b/spec/graphql/types/work_type_spec.rb @@ -1345,135 +1345,4 @@ ) end end - - describe "query fields with __other__ and __missing__ data", elasticsearch: true do - let(:query) do - "query($first: Int, $cursor: String, $facetCount: Int) { - works(first: $first, after: $cursor, facetCount: $facetCount) { - totalCount - resourceTypes { - id - title - count - } - affiliations { - id - title - count - } - licenses { - id - title - count - } - } - }" - end - - let!(:works_5) do - create_list(:doi, 5, aasm_state: "findable", - types: { "resourceTypeGeneral" => "Text" }, - creators: [{ - affiliation: [{ - "name": "5", - "affiliationIdentifier": "https://ror.org/5", - "affiliationIdentifierScheme": "ROR", - }], - }], - rights_list: [{ "rightsIdentifier" => "cc-by-1.0" }] - ) - end - let!(:works_4) do - create_list(:doi, 4, aasm_state: "findable", - types: { "resourceTypeGeneral" => "JournalArticle" }, - creators: [{ - affiliation: [{ - "name": "4", - "affiliationIdentifier": "https://ror.org/4", - "affiliationIdentifierScheme": "ROR", - }], - }], - rights_list: [{ "rightsIdentifier" => "cc-by-2.0" }] - ) - end - let!(:works_3) do - create_list(:doi, 3, aasm_state: "findable", - types: { "resourceTypeGeneral" => "Image" }, - creators: [{ - affiliation: [{ - "name": "3", - "affiliationIdentifier": "https://ror.org/3", - "affiliationIdentifierScheme": "ROR", - }], - }], - rights_list: [{ "rightsIdentifier" => "cc-by-2.5" }] - ) - end - let!(:works_2) do - create_list(:doi, 2, aasm_state: "findable", - types: { "resourceTypeGeneral" => "PhysicalObject" }, - creators: [{ - affiliation: [{ - "name": "2", - "affiliationIdentifier": "https://ror.org/2", - "affiliationIdentifierScheme": "ROR", - }], - }], - rights_list: [{ "rightsIdentifier" => "cc-by-3.0" }] - ) - end - let!(:works_other) do - create(:doi, aasm_state: "findable", - types: { "resourceTypeGeneral" => "Preprint" }, - creators: [{ - affiliation: [ - { - "name": "1", - "affiliationIdentifier": "https://ror.org/1", - "affiliationIdentifierScheme": "ROR", - }, - { - "name": "0", - "affiliationIdentifier": "https://ror.org/0", - "affiliationIdentifierScheme": "ROR", - } - ], - }], - rights_list: [ - { "rightsIdentifier" => "bsd-2-clause" }, - { "rightsIdentifier" => "bsd-3-clause" }, - ]) - end - let!(:missing) do - create_list(:doi, 3, aasm_state: "findable", - creators: [{ affiliation: [] }], - rights_list: []) - end - - before do - Doi.import - sleep 2 - @works = Doi.gql_query(nil, page: { cursor: [], size: 11 }).results.to_a - end - - it "returns all works" do - response = - LupoSchema.execute( - query, - variables: { first: 4, cursor: nil, facetCount: 5 } - ). - as_json - - expect(response.dig("data", "works", "totalCount")).to eq(18) - expect(response.dig("data", "works", "resourceTypes")).to eq( - [{ "count" => 5, "id" => "text", "title" => "Text" }, { "count" => 4, "id" => "journal-article", "title" => "Journal Article" }, { "count" => 3, "id" => "dataset", "title" => "Dataset" }, { "count" => 3, "id" => "image", "title" => "Image" }, { "count" => 2, "id" => "physical-object", "title" => "Physical Object" }, { "count" => 1, "id" => "__other__", "title" => "Other" }] - ) - expect(response.dig("data", "works", "affiliations")).to eq( - [{ "count" => 5, "id" => "ror.org/5", "title" => "5" }, { "count" => 4, "id" => "ror.org/4", "title" => "4" }, { "count" => 3, "id" => "__missing__", "title" => "Missing" }, { "count" => 3, "id" => "ror.org/3", "title" => "3" }, { "count" => 2, "id" => "ror.org/2", "title" => "2" }, { "count" => 2, "id" => "__other__", "title" => "Other" }] - ) - expect(response.dig("data", "works", "licenses")).to eq( - [{ "count" => 5, "id" => "cc-by-1.0", "title" => "CC-BY-1.0" }, { "count" => 4, "id" => "cc-by-2.0", "title" => "CC-BY-2.0" }, { "count" => 3, "id" => "__missing__", "title" => "Missing" }, { "count" => 3, "id" => "cc-by-2.5", "title" => "CC-BY-2.5" }, { "count" => 2, "id" => "cc-by-3.0", "title" => "CC-BY-3.0" }, { "count" => 2, "id" => "__other__", "title" => "Other" }] - ) - end - end end