Skip to content

Commit dc4f305

Browse files
authored
Add authors facet (#1316)
* add authors facet * add test for authors facet * remove contributorType from creators
1 parent b8bdba0 commit dc4f305

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

app/controllers/datacite_dois_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def index
239239
licenses_with_missing: :facet_by_license_and_other,
240240
schema_versions: :facet_by_schema,
241241
link_checks_status: :facet_by_cumulative_year,
242+
authors: :facet_by_authors,
242243
creators_and_contributors: :facet_by_creators_and_contributors,
243244
subjects: :facet_by_key,
244245
fields_of_science: :facet_by_fos,

app/models/doi.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,24 @@ def as_indexed_json(_options = {})
726726
licenses_with_missing: { terms: { field: "rights_list.rightsIdentifier", size: 10, min_doc_count: 1, missing: "__missing__" } },
727727
languages: { terms: { field: "language", size: 10, min_doc_count: 1 } },
728728
certificates: { terms: { field: "client.certificate", size: 10, min_doc_count: 1 } },
729+
authors: {
730+
terms: {
731+
field: "creators.nameIdentifiers.nameIdentifier",
732+
size: 10,
733+
min_doc_count: 1,
734+
include: "https?://orcid.org/.*"
735+
},
736+
aggs: {
737+
authors: {
738+
top_hits: {
739+
_source: {
740+
includes: [ "creators.name", "creators.nameIdentifiers.nameIdentifier"]
741+
},
742+
size: 1
743+
}
744+
}
745+
}
746+
},
729747
creators_and_contributors: {
730748
terms: {
731749
field: "creators_and_contributors.nameIdentifiers.nameIdentifier",

spec/requests/datacite_dois/datacite_dois_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,4 +1648,64 @@ def clear_doi_index
16481648
expect(json.dig("meta", "licensesWithMissing", 1, "id")).to eq("__missing__")
16491649
end
16501650
end
1651+
1652+
describe "GET /dois search with author values", prefix_pool_size: 1 do
1653+
let!(:dois) { create_list(:doi, 10, client: client, aasm_state: "findable") }
1654+
let!(:dois_with_creators) do
1655+
create_list(:doi, 3, client: client, aasm_state: "findable",
1656+
creators: [
1657+
{
1658+
"name" => "TEST CREATOR 1",
1659+
"nameIdentifiers" => [
1660+
{
1661+
"nameIdentifier" => "https://orcid.org/0000-0003-3484-6874",
1662+
"nameIdentifierScheme" => "ORCID",
1663+
"schemeUri" => "https://orcid.org",
1664+
},
1665+
],
1666+
},
1667+
{
1668+
"name" => "TEST CREATOR 2",
1669+
"nameIdentifiers" => [
1670+
{
1671+
"nameIdentifier" => "https://orcid.org/0000-0003-3484-6875",
1672+
"nameIdentifierScheme" => "ORCID",
1673+
"schemeUri" => "https://orcid.org",
1674+
},
1675+
],
1676+
}
1677+
]
1678+
)
1679+
end
1680+
let!(:dois_with_contributors) do
1681+
create_list(:doi, 3, client: client, aasm_state: "findable",
1682+
contributors: [
1683+
{
1684+
"contributorType" => "Editor",
1685+
"name" => "TEST CONTRIBUTOR",
1686+
"nameIdentifiers" => [
1687+
{
1688+
"nameIdentifier" => "https://orcid.org/0000-0003-3484-6876",
1689+
"nameIdentifierScheme" => "ORCID",
1690+
"schemeUri" => "https://orcid.org",
1691+
},
1692+
],
1693+
}
1694+
]
1695+
)
1696+
end
1697+
1698+
before do
1699+
clear_doi_index
1700+
import_doi_index
1701+
end
1702+
1703+
it "returns author values" do
1704+
get "/dois?facets=authors", nil, headers
1705+
1706+
expect(last_response.status).to eq(200)
1707+
expect(json.dig("meta", "authors")).to be_truthy
1708+
expect(json.dig("meta", "authors").length()).to eq(3)
1709+
end
1710+
end
16511711
end

0 commit comments

Comments
 (0)