diff --git a/app/models/doi.rb b/app/models/doi.rb index 97f310d1f..0fa2926c3 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -668,7 +668,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__" } }, authors: { - terms: { field: "creators.nameIdentifiers.nameIdentifier", size: facet_count, min_doc_count: 1 }, + terms: { field: "creators.nameIdentifiers.nameIdentifier", size: facet_count, min_doc_count: 1, include: "https?://orcid.org/.*" }, aggs: { authors: { top_hits: { @@ -681,7 +681,7 @@ def self.gql_query_aggregations(facet_count: 10) } }, creators_and_contributors: { - terms: { field: "creators_and_contributors.nameIdentifiers.nameIdentifier", size: facet_count, min_doc_count: 1 }, + terms: { field: "creators_and_contributors.nameIdentifiers.nameIdentifier", size: facet_count, min_doc_count: 1, include: "https?://orcid.org/.*" }, aggs: { creators_and_contributors: { top_hits: { diff --git a/spec/graphql/types/work_type_spec.rb b/spec/graphql/types/work_type_spec.rb index bf8173d6d..8af78bb3b 100644 --- a/spec/graphql/types/work_type_spec.rb +++ b/spec/graphql/types/work_type_spec.rb @@ -1711,4 +1711,135 @@ expect(response.dig("data", "works", "creatorsAndContributors").length()).to eq(2) end end + + + describe "query contributors with a mix of ORCID iDs and local identifiers", elasticsearch: true do + let!(:work) do + create( + :doi, + aasm_state: "findable", + creators: [ + { + "givenName" => "Cody", + "familyName" => "Ross", + "name" => "Ross, Cody", + "nameIdentifiers" => [{ + "nameIdentifier" => "local identifier 1", + "nameIdentifierScheme" => "local", + "schemeUri" => "https://test.org", + }], + }, + { + "name" => "Test Author", + "nameType" => "Personal", + "nameIdentifiers" => [{ + "nameIdentifier" => "local identifier 2", + "nameIdentifierScheme" => "local", + "schemeUri" => "test.org", + }], + }, + { + "name" => "Bryceson Laing", + "nameType" => "Personal", + "nameIdentifiers" => [{ + "nameIdentifier" => "https://orcid.org/0000-0002-8249-1629", + "nameIdentifierScheme" => "ORCID", + "schemeUri" => "https://orcid.org", + }], + }, + ], + contributors: [ + { + "name": "Contributor", + "nameType": "Personal", + "givenName": "Test 1", + "familyName": "Contributor", + "nameIdentifiers": [ + { + "schemeUri": "", + "nameIdentifier": "7482", + "nameIdentifierScheme": "local" + } + ], + "contributorType" => "Editor" + }, + { + "name": "Contributor", + "nameType": "Personal", + "givenName": "Test 2", + "familyName": "Contributor", + "nameIdentifiers": [ + { + "schemeUri": "", + "nameIdentifier": "7482", + "nameIdentifierScheme": "local" + }, + ], + "contributorType" => "Editor" + }, + { + "name": "Joseph Rhoads", + "nameType": "Personal", + "givenName": "Joseph", + "familyName": "Rhoads", + "nameIdentifiers": [ + { + "schemeUri": "", + "nameIdentifier": "7483", + "nameIdentifierScheme": "local" + }, + { + "schemeUri": "https://orcid.org", + "nameIdentifier": "https://orcid.org/0000-0003-3484-6876", + "nameIdentifierScheme": "ORCID" + } + ], + "contributorType" => "Editor" + } + ] + ) + end + + before do + Doi.import + sleep 2 + end + + let(:query) do + "query($first: Int, $cursor: String, $facetCount: Int) { + works(first: $first, after: $cursor, facetCount: $facetCount) { + totalCount + authors { + id + title + count + } + creatorsAndContributors { + id + title + count + } + } + }" + end + + it "returns the correct counts for authors, filtering out those that don't include ORCID iDs" do + response = LupoSchema.execute( + query, + variables: { first: nil, cursor: nil, facetCount: 3 } + ).as_json + + expect(response.dig("data", "works", "authors").length()).to eq(1) + end + + + it "returns the correct counts for creatorsAndContributors, filtering out those that don't include ORCID iDs" do + response = LupoSchema.execute( + query, + variables: { first: nil, cursor: nil, facetCount: 3 } + ).as_json + + expect(response.dig("data", "works", "creatorsAndContributors").length()).to eq(2) + end + end end