diff --git a/app/models/doi/graphql_query.rb b/app/models/doi/graphql_query.rb index e7e899e21..46611b534 100644 --- a/app/models/doi/graphql_query.rb +++ b/app/models/doi/graphql_query.rb @@ -30,7 +30,7 @@ def size end def sort - DEFAULT_SORT + DEFAULT_SORT end def query_fields diff --git a/spec/models/doi/graphql_query_builder_aggregates_spec.rb b/spec/models/doi/graphql_query_builder_aggregates_spec.rb index d3853eebe..9c10e0911 100644 --- a/spec/models/doi/graphql_query_builder_aggregates_spec.rb +++ b/spec/models/doi/graphql_query_builder_aggregates_spec.rb @@ -11,110 +11,110 @@ 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}, + 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}}, + 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, + 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, + 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)"}, + 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_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, + 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, + 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, + languages: { + terms: { + field: "language", + min_doc_count: 1, + size: 10, }, }, - :licenses=>{ - :terms=>{ - :field=>"rights_list.rightsIdentifier", - :min_doc_count=>1, - :missing=>"__missing__", - :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, + open_licenses: { + aggs: { + resource_types: { + terms: { + field: "resource_type_id_and_name", + min_doc_count: 1, + size: 10, }, }, }, - :filter=>{ - :terms=>{:"rights_list.rightsIdentifier"=>[ + filter: { + terms: { "rights_list.rightsIdentifier": [ "cc-by-1.0", "cc-by-2.0", "cc-by-2.5", @@ -125,15 +125,15 @@ "cc-pddc", "cc0-1.0", "cc-pdm-1.0", - ]}, + ] }, }, }, - :pid_entities=>{ - :aggs=>{ - :subject=>{ - :terms=>{ - :field=>"subjects.subject", - :include=>[ + pid_entities: { + aggs: { + subject: { + terms: { + field: "subjects.subject", + include: [ "Dataset", "Publication", "Software", @@ -146,33 +146,33 @@ "Repository", "Project", ], - :min_doc_count=>1, - :size=>10, + 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"}, + 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}, + 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"}, + resource_types: { terms: { + field: "resource_type_id_and_name", + min_doc_count: 1, + missing: "__missing__", + size: 10, + } }, + view_count: { + sum: { field: "view_count" }, }, } ) @@ -206,7 +206,4 @@ expect(builder.aggregations.keys).to match_array(expected_keys) end end - - - end diff --git a/spec/models/doi/graphql_query_builder_filters_spec.rb b/spec/models/doi/graphql_query_builder_filters_spec.rb index 84aa88316..261ef7af2 100644 --- a/spec/models/doi/graphql_query_builder_filters_spec.rb +++ b/spec/models/doi/graphql_query_builder_filters_spec.rb @@ -10,115 +10,112 @@ describe "filters" do context "with basic filters" do - it "handles DOI ids" do - options = { ids: "10.5438/0012,10.5438/0013" } - builder = described_class.new(query, options) - expect(builder.filters).to include( - { terms: { doi: ["10.5438/0012", "10.5438/0013"].map(&:upcase) } } - ) - end - - it "handles resource_type_id" do - options = { resource_type_id: "Journal_Article" } - builder = described_class.new(query, options) - expect(builder.filters).to include( - { term: { resource_type_id: "journal-article" } } - ) - - end + it "handles DOI ids" do + options = { ids: "10.5438/0012,10.5438/0013" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { terms: { doi: ["10.5438/0012", "10.5438/0013"].map(&:upcase) } } + ) + end - it "handles resource type" do - options = { resource_type: "dataset,text" } - builder = described_class.new(query, options) - expect(builder.filters).to include( - { terms: { "types.resourceType": ["dataset", "text"] } } - ) - end + it "handles resource_type_id" do + options = { resource_type_id: "Journal_Article" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { term: { resource_type_id: "journal-article" } } + ) + end + it "handles resource type" do + options = { resource_type: "dataset,text" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { terms: { "types.resourceType": ["dataset", "text"] } } + ) + end - it "handles agency" do - options = {agency: "crossref"} - builder = described_class.new(query, options) - expect(builder.filters).to include( - { terms: { agency: ["crossref"].map(&:downcase) } } - ) - end - it "handles prefix" do - options = {prefix: "10.5438"} - builder = described_class.new(query, options) - expect(builder.filters).to include( - { terms: { prefix: ["10.5438"].map(&:downcase) } } - ) - end + it "handles agency" do + options = { agency: "crossref" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { terms: { agency: ["crossref"].map(&:downcase) } } + ) + end - it "handles language" do - options = { language: "en,de" } - builder = described_class.new(query, options) - expect(builder.filters).to include( - { terms: { language: ["en", "de"].map(&:downcase) } } - ) - end + it "handles prefix" do + options = { prefix: "10.5438" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { terms: { prefix: ["10.5438"].map(&:downcase) } } + ) + end - it "handles uid" do - options = { uid: "10.5438/0012" } - builder = described_class.new(query, options) - expect(builder.filters).to include( - { term: { uid: "10.5438/0012" } } - ) - end + it "handles language" do + options = { language: "en,de" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { terms: { language: ["en", "de"].map(&:downcase) } } + ) + end - it "handles state" do - options = { state: "findable,registered" } - builder = described_class.new(query, options) - expect(builder.filters).to include( - { terms: { aasm_state: ["findable", "registered"] } } - ) - end + it "handles uid" do + options = { uid: "10.5438/0012" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { term: { uid: "10.5438/0012" } } + ) + end - it "handles consortium_id" do - options = { consortium_id: "dc" } - builder = described_class.new(query, options) - expect(builder.filters).to include( - { term: { consortium_id: { :case_insensitive => true, :value => "dc" } } } - ) - end + it "handles state" do + options = { state: "findable,registered" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { terms: { aasm_state: ["findable", "registered"] } } + ) + end - it "handles registered" do - options = { registered: "2021,2023" } - builder = described_class.new(query, options) - expect(builder.filters).to include( - { range: { registered: { gte: "2021||/y", lte: "2023||/y", format: "yyyy" } } } - ) - end + it "handles consortium_id" do + options = { consortium_id: "dc" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { term: { consortium_id: { case_insensitive: true, value: "dc" } } } + ) + end + it "handles registered" do + options = { registered: "2021,2023" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { range: { registered: { gte: "2021||/y", lte: "2023||/y", format: "yyyy" } } } + ) + end end context "filters based on client metadata" do - it "handles re3data_id" do - options = { re3data_id: "10.17616/r31njmjx" } - builder = described_class.new(query, options) - expect(builder.filters).to include( - { term: { "client.re3data_id" => "10.17616/r31njmjx" } } - ) - end - - it "handles opendoar_id" do - options = { opendoar_id: "123456" } - builder = described_class.new(query, options) - expect(builder.filters).to include( - { term: { "client.opendoar_id" => "123456" } } - ) - end + it "handles re3data_id" do + options = { re3data_id: "10.17616/r31njmjx" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { term: { "client.re3data_id" => "10.17616/r31njmjx" } } + ) + end - it "handles certificates" do - options = { certificate: "CoreTrustSeal,WDS" } - builder = described_class.new(query, options) - expect(builder.filters).to include( - { terms: { "client.certificate" => ["CoreTrustSeal", "WDS"] } } - ) - end + it "handles opendoar_id" do + options = { opendoar_id: "123456" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { term: { "client.opendoar_id" => "123456" } } + ) + end + it "handles certificates" do + options = { certificate: "CoreTrustSeal,WDS" } + builder = described_class.new(query, options) + expect(builder.filters).to include( + { terms: { "client.certificate" => ["CoreTrustSeal", "WDS"] } } + ) + end end context "with date range filters" do @@ -304,8 +301,5 @@ expect(builder.filters).to be_empty end end - - - end end diff --git a/spec/models/doi/graphql_query_builder_spec.rb b/spec/models/doi/graphql_query_builder_spec.rb index 683eb74a6..034adcbcf 100644 --- a/spec/models/doi/graphql_query_builder_spec.rb +++ b/spec/models/doi/graphql_query_builder_spec.rb @@ -69,9 +69,7 @@ let(:options) { { sort: "relevance" } } it "ignores any sort options and returns the default" do expect(builder.sort).to eq(described_class::DEFAULT_SORT) - end end end - end