-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
212 additions
and
0 deletions.
There are no files selected for viewing
212 changes: 212 additions & 0 deletions
212
spec/models/doi/graphql_query_builder_aggregates_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Doi::GraphqlQuery::Builder do | ||
let(:query) { "" } | ||
let(:options) { {} } | ||
|
||
describe "aggregations" do | ||
it "by default all aggregations are enabled" do | ||
builder = described_class.new(query, options) | ||
expect(builder.aggregations).to eq( | ||
{ | ||
:affiliations=>{:terms=>{:field=>"affiliation_id_and_name", :min_doc_count=>1, :missing=>"__missing__", :size=>10}}, | ||
:authors=>{ | ||
:aggs=>{:authors=>{ | ||
:top_hits=>{:_source=>{ | ||
:includes=>["creators.name", "creators.nameIdentifiers.nameIdentifier"], | ||
}, :size=>1}, | ||
}}, | ||
:terms=>{:field=>"creators.nameIdentifiers.nameIdentifier", :include=>"https?://orcid.org/.*", :min_doc_count=>1, :size=>10}, | ||
}, | ||
:citation_count=>{ | ||
:sum=>{:field=>"citation_count"}, | ||
}, | ||
:client_types=>{ | ||
:terms=>{:field=>"client.client_type", :min_doc_count=>1, :size=>10}, | ||
}, | ||
:clients=>{ | ||
:terms=>{:field=>"client_id_and_name", :min_doc_count=>1, :size=>10}, | ||
}, | ||
:content_url_count=>{ | ||
:value_count=>{:field=>"content_url"}, | ||
}, | ||
:creators_and_contributors=>{ | ||
:aggs=>{ | ||
:creators_and_contributors=>{ | ||
:top_hits=>{:_source=>{ | ||
:includes=>["creators_and_contributors.name", "creators_and_contributors.nameIdentifiers.nameIdentifier"], | ||
}, :size=>1}, | ||
}, | ||
:work_types=>{:terms=>{:field=>"resource_type_id_and_name", :min_doc_count=>1}}, | ||
}, | ||
:terms=>{ | ||
:field=>"creators_and_contributors.nameIdentifiers.nameIdentifier", | ||
:include=>"https?://orcid.org/.*", | ||
:min_doc_count=>1, | ||
:size=>10, | ||
}, | ||
}, | ||
:download_count=>{ | ||
:sum=>{:field=>"download_count"}, | ||
}, | ||
:fields_of_science=>{ | ||
:aggs=>{ | ||
:subject=>{ | ||
:terms=>{ | ||
:field=>"subjects.subject", | ||
:include=>"FOS:.*", | ||
:min_doc_count=>1, | ||
:size=>10, | ||
}, | ||
}, | ||
}, | ||
:filter=>{ | ||
:term=>{:"subjects.subjectScheme"=>"Fields of Science and Technology (FOS)"}, | ||
}, | ||
}, | ||
:fields_of_science_combined=>{ | ||
:terms=>{ | ||
:field=>"fields_of_science_combined", | ||
:min_doc_count=>1, | ||
:size=>10, | ||
}, | ||
}, | ||
:fields_of_science_repository=>{ | ||
:terms=>{ | ||
:field=>"fields_of_science_repository", | ||
:min_doc_count=>1, | ||
:size=>10, | ||
}, | ||
}, | ||
:funders=>{ | ||
:aggs=>{:funders=>{:top_hits=>{:_source=>{:includes=>["funding_references.funderName", "funding_references.funderIdentifier"]}, :size=>1}}}, | ||
:terms=>{ | ||
:field=>"funding_references.funderIdentifier", | ||
:min_doc_count=>1, | ||
:size=>10, | ||
}, | ||
}, | ||
:languages=>{ | ||
:terms=>{ | ||
:field=>"language", | ||
:min_doc_count=>1, | ||
:size=>10, | ||
}, | ||
}, | ||
:licenses=>{ | ||
:terms=>{ | ||
:field=>"rights_list.rightsIdentifier", | ||
:min_doc_count=>1, | ||
:missing=>"__missing__", | ||
:size=>10, | ||
}, | ||
}, | ||
:open_licenses=>{ | ||
:aggs=>{ | ||
:resource_types=>{ | ||
:terms=>{ | ||
:field=>"resource_type_id_and_name", | ||
:min_doc_count=>1, | ||
:size=>10, | ||
}, | ||
}, | ||
}, | ||
: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", | ||
]}, | ||
}, | ||
}, | ||
:pid_entities=>{ | ||
:aggs=>{ | ||
:subject=>{ | ||
:terms=>{ | ||
:field=>"subjects.subject", | ||
:include=>[ | ||
"Dataset", | ||
"Publication", | ||
"Software", | ||
"Organization", | ||
"Funder", | ||
"Person", | ||
"Grant", | ||
"Sample", | ||
"Instrument", | ||
"Repository", | ||
"Project", | ||
], | ||
:min_doc_count=>1, | ||
:size=>10, | ||
}, | ||
}, | ||
}, | ||
:filter=>{:term=>{:"subjects.subjectScheme"=>"PidEntity"}}, | ||
}, | ||
:published=>{ | ||
:date_histogram=>{ | ||
:field=>"publication_year", | ||
:format=>"year", | ||
:interval=>"year", | ||
:min_doc_count=>1, | ||
:order=>{:_key=>"desc"}, | ||
}, | ||
}, | ||
:registration_agencies=>{ | ||
:terms=>{:field=>"agency", :min_doc_count=>1, :size=>10}, | ||
}, | ||
:resource_types=>{:terms=>{ | ||
:field=>"resource_type_id_and_name", | ||
:min_doc_count=>1, | ||
:missing=>"__missing__", | ||
:size=>10, | ||
}}, | ||
:view_count=>{ | ||
:sum=>{:field=>"view_count"}, | ||
}, | ||
} | ||
) | ||
end | ||
|
||
it "has keys for all aggregates" do | ||
expected_keys = %i[ | ||
affiliations | ||
authors | ||
citation_count | ||
client_types | ||
clients | ||
content_url_count | ||
creators_and_contributors | ||
download_count | ||
fields_of_science | ||
fields_of_science_combined | ||
fields_of_science_repository | ||
funders | ||
languages | ||
licenses | ||
open_licenses | ||
pid_entities | ||
published | ||
registration_agencies | ||
resource_types | ||
view_count | ||
] | ||
|
||
builder = described_class.new(query, options) | ||
expect(builder.aggregations.keys).to match_array(expected_keys) | ||
end | ||
end | ||
|
||
|
||
|
||
end |