Skip to content

Commit

Permalink
Merge pull request #989 from datacite/contributors-filter-bug
Browse files Browse the repository at this point in the history
Fix contributors missing from filter
  • Loading branch information
bklaing2 authored Jul 31, 2023
2 parents 38c5b53 + 5232283 commit c5257fd
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
131 changes: 131 additions & 0 deletions spec/graphql/types/work_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c5257fd

Please sign in to comment.