diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index c217a8312..698d8c897 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -531,6 +531,28 @@ def facet_by_creators_and_contributors(arr) _facet_by_general_contributor(arr, "creators_and_contributors", "creators_and_contributors") end + def multi_facet_by_contributors_and_worktype(arr) + outer = _facet_by_general_contributor(arr, "creators_and_contributors", "creators_and_contributors") + outer.map do |hsh| + creator_hash = arr.find { |h| h["key"] == hsh["id"] } + inner = facet_by_combined_key(creator_hash.dig("work_types", "buckets")) + hsh.merge("inner" => inner) + end + end + + def flatten_muti_facet(arr) + arr.map do |hsh| + outer_title = hsh["title"] + inner = hsh.fetch("inner", []) + inner.map do |ihsh| + { + "data" => [outer_title, ihsh["title"]], + "count" => ihsh["count"] + } + end + end.flatten + end + def add_other(arr, other_count) if other_count > 0 arr << { diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 5cc6d395b..ec1921f25 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -412,6 +412,8 @@ type AudiovisualConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -1010,6 +1012,8 @@ type BookChapterConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -1060,6 +1064,8 @@ type BookConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -1432,6 +1438,8 @@ type CollectionConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -1756,6 +1764,8 @@ type ConferencePaperConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -2372,6 +2382,8 @@ type DataManagementPlanConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -2696,6 +2708,8 @@ type DataPaperConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -3045,6 +3059,8 @@ type DatasetConnectionWithTotal implements WorkFacetsInterface { """ pageInfo: PageInfo! personConnectionCount: Int! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] publicationConnectionCount: Int! published: [Facet!] registrationAgencies: [Facet!] @@ -3462,6 +3478,8 @@ type DissertationConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -4477,6 +4495,21 @@ type FieldOfScience { name: String } +""" +Flattened Count Type for Multi-level Facets +""" +type FlattenedCount { + """ + Count + """ + count: Int + + """ + Flattened facets + """ + data: [String!] +} + """ Information about funders """ @@ -5015,6 +5048,8 @@ type ImageConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -5339,6 +5374,8 @@ type InstrumentConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -5663,6 +5700,8 @@ type InteractiveResourceConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -5992,6 +6031,8 @@ type JournalArticleConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -6612,6 +6653,8 @@ type ModelConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -6633,6 +6676,31 @@ type ModelEdge { node: Model } +""" +Multi-level Facets +""" +type MultiFacet { + """ + Count + """ + count: Int + + """ + ID + """ + id: String + + """ + Inner facets + """ + inner: [Facet!] + + """ + Title + """ + title: String +} + type Mutation { createClaim(doi: ID!, id: ID, sourceId: String): CreateClaimPayload! deleteClaim(id: ID!): DeleteClaimPayload! @@ -7108,6 +7176,8 @@ type OtherConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -7457,6 +7527,8 @@ type PeerReviewConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -7918,6 +7990,8 @@ type PhysicalObjectConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -8295,6 +8369,8 @@ type PreprintConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -8623,6 +8699,8 @@ type PublicationConnectionWithTotal implements WorkFacetsInterface { """ pageInfo: PageInfo! personConnectionCount: Int! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] publicationConnectionCount: Int! published: [Facet!] registrationAgencies: [Facet!] @@ -9588,6 +9666,8 @@ type ServiceConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] pidEntities: [Facet!] published: [Facet!] registrationAgencies: [Facet!] @@ -9942,6 +10022,8 @@ type SoftwareConnectionWithTotal implements WorkFacetsInterface { """ pageInfo: PageInfo! personConnectionCount: Int! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] publicationConnectionCount: Int! published: [Facet!] registrationAgencies: [Facet!] @@ -10268,6 +10350,8 @@ type SoundConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -10803,6 +10887,8 @@ type WorkConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -10839,6 +10925,8 @@ interface WorkFacetsInterface { languages: [Facet!] licenses: [Facet!] openLicenseResourceTypes: [Facet!] + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] @@ -11148,6 +11236,8 @@ type WorkflowConnectionWithTotal implements WorkFacetsInterface { Information to aid in pagination. """ pageInfo: PageInfo! + personToWorkTypesFlat: [FlattenedCount!] + personToWorkTypesMultilevel: [MultiFacet!] published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] diff --git a/app/graphql/types/flattened_count_type.rb b/app/graphql/types/flattened_count_type.rb new file mode 100644 index 000000000..f32cb3e6e --- /dev/null +++ b/app/graphql/types/flattened_count_type.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class FlattenedCountType < BaseObject + description "Flattened Count Type for Multi-level Facets" + + field :count, Int, null: true, description: "Count" + field :data, [String], null: true, description: "Flattened facets" +end diff --git a/app/graphql/types/interfaces/work_facets_interface.rb b/app/graphql/types/interfaces/work_facets_interface.rb index 47a736e90..389a7a1f3 100644 --- a/app/graphql/types/interfaces/work_facets_interface.rb +++ b/app/graphql/types/interfaces/work_facets_interface.rb @@ -19,6 +19,27 @@ module Interfaces::WorkFacetsInterface field :fields_of_science_repository, [FacetType], null: true, cache: true field :licenses, [FacetType], null: true, cache: true field :languages, [FacetType], null: true, cache: true + field :person_to_work_types_multilevel, [MultiFacetType], null: true, cache: true + field :person_to_work_types_flat, [FlattenedCountType], null: true, cache: true + + def person_to_work_types_multilevel + if object.aggregations.creators_and_contributors + multi_facet_by_contributors_and_worktype(object.aggregations.creators_and_contributors.buckets) + else + [] + end + end + + def person_to_work_types_flat + if object.aggregations.creators_and_contributors + contributors_works = multi_facet_by_contributors_and_worktype( + object.aggregations.creators_and_contributors.buckets + ) + flatten_muti_facet(contributors_works) + else + [] + end + end def total_count object.total_count diff --git a/app/graphql/types/multi_facet_type.rb b/app/graphql/types/multi_facet_type.rb new file mode 100644 index 000000000..557236f41 --- /dev/null +++ b/app/graphql/types/multi_facet_type.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class MultiFacetType < BaseObject + description "Multi-level Facets" + + field :id, String, null: true, description: "ID" + field :title, String, null: true, description: "Title" + field :count, Int, null: true, description: "Count" + field :inner, [FacetType], null: true, description: "Inner facets" +end diff --git a/app/models/doi/graphql_query.rb b/app/models/doi/graphql_query.rb index 2399d7652..9ceed18f7 100644 --- a/app/models/doi/graphql_query.rb +++ b/app/models/doi/graphql_query.rb @@ -260,7 +260,20 @@ def aggregations resource_types: { terms: { field: "resource_type_id_and_name", size: facet_count, min_doc_count: 1, missing: "__missing__" } }, clients: { terms: { field: "client_id_and_name", size: facet_count, min_doc_count: 1 } }, open_licenses: { - 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"] } }, + 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" + ] + } }, aggs: { resource_types: { terms: { field: "resource_type_id_and_name", size: facet_count, min_doc_count: 1 } @@ -294,15 +307,29 @@ def aggregations } }, creators_and_contributors: { - terms: { field: "creators_and_contributors.nameIdentifiers.nameIdentifier", size: facet_count, min_doc_count: 1, include: "https?://orcid.org/.*" }, + terms: { + field: "creators_and_contributors.nameIdentifiers.nameIdentifier", + size: facet_count, + min_doc_count: 1, + include: "https?://orcid.org/.*" + }, aggs: { creators_and_contributors: { top_hits: { _source: { - includes: [ "creators_and_contributors.name", "creators_and_contributors.nameIdentifiers.nameIdentifier"] + 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 + } } } }, @@ -329,8 +356,24 @@ def aggregations pid_entities: { filter: { term: { "subjects.subjectScheme": "PidEntity" } }, aggs: { - subject: { terms: { field: "subjects.subject", size: facet_count, min_doc_count: 1, - include: %w(Dataset Publication Software Organization Funder Person Grant Sample Instrument Repository Project) } }, + subject: { terms: { + field: "subjects.subject", + size: facet_count, + min_doc_count: 1, + include: %w( + Dataset + Publication + Software + Organization + Funder + Person + Grant + Sample + Instrument + Repository + Project + ) + } }, }, }, fields_of_science: { diff --git a/spec/concerns/facetable_spec.rb b/spec/concerns/facetable_spec.rb index 819ad7677..17aa64376 100644 --- a/spec/concerns/facetable_spec.rb +++ b/spec/concerns/facetable_spec.rb @@ -7,6 +7,7 @@ let(:author_aggs_with_multiple_name_identifiers) { JSON.parse(file_fixture("authors_aggs_with_multiple_name_identifiers.json").read) } let(:model) { DataciteDoisController.new } let(:funder_aggs) { JSON.parse(file_fixture("funders_aggs.json").read) } + let(:contributor_worktype_multiaggs) { JSON.parse(file_fixture("contributor_worktype_multi_aggs.json").read) } it "facet by author" do authors = model.facet_by_authors(author_aggs) @@ -83,6 +84,88 @@ expect(funders).to eq (expected_result) end + + it "multifacet by contributor-worktype combinations" do + contributors_works = model.multi_facet_by_contributors_and_worktype(contributor_worktype_multiaggs) + + + expected_results = [ + { "count" => 98, + "id" => "https://orcid.org/0000-0003-1419-2405", + "inner" => + [{ "count" => 75, "id" => "text", "title" => "Text" }, + { "count" => 15, "id" => "software", "title" => "Software" }, + { "count" => 4, "id" => "collection", "title" => "Collection" }, + { "count" => 1, "id" => "computational-notebook", "title" => "Computational Notebook" }, + { "count" => 1, "id" => "dataset", "title" => "Dataset" }, + { "count" => 1, "id" => "report", "title" => "Report" }, + { "count" => 1, "id" => "service", "title" => "Service" }], + "title" => "Fenner, Martin" }, + { "count" => 37, + "id" => "https://orcid.org/0000-0001-6660-6214", + "inner" => + [{ "count" => 34, "id" => "text", "title" => "Text" }, + { "count" => 1, "id" => "audiovisual", "title" => "Audiovisual" }, + { "count" => 1, + "id" => "output-management-plan", + "title" => "Output Management Plan" }, + { "count" => 1, "id" => "service", "title" => "Service" }], + "title" => "Cousijn, Helena" }, + { "count" => 29, + "id" => "https://orcid.org/0000-0002-4695-7874", + "inner" => + [{ "count" => 28, "id" => "text", "title" => "Text" }, + { "count" => 1, "id" => "collection", "title" => "Collection" }], + "title" => "Dasler, Robin" }, + { "count" => 29, + "id" => "https://orcid.org/0000-0003-4448-3844", + "inner" => + [{ "count" => 27, "id" => "text", "title" => "Text" }, + { "count" => 1, "id" => "other", "title" => "Other" }, + { "count" => 1, "id" => "report", "title" => "Report" }], + "title" => "Vierkant, Paul" }, + { "count" => 28, + "id" => "https://orcid.org/0000-0003-3484-6875", + "inner" => + [{ "count" => 21, "id" => "text", "title" => "Text" }, + { "count" => 4, "id" => "software", "title" => "Software" }, + { "count" => 2, "id" => "collection", "title" => "Collection" }, + { "count" => 1, "id" => "other", "title" => "Other" }], + "title" => "Garza, Kristian" }] + + expect(contributors_works).to eq (expected_results) + end + + it "flattened multifacet contributor-worktype combinations" do + contributors_works = model.multi_facet_by_contributors_and_worktype(contributor_worktype_multiaggs) + flattened_contributors_works = model.flatten_muti_facet(contributors_works) + + expected_results = [ + { "count" => 75, "data" => ["Fenner, Martin", "Text"] }, + { "count" => 15, "data" => ["Fenner, Martin", "Software"] }, + { "count" => 4, "data" => ["Fenner, Martin", "Collection"] }, + { "count" => 1, "data" => ["Fenner, Martin", "Computational Notebook"] }, + { "count" => 1, "data" => ["Fenner, Martin", "Dataset"] }, + { "count" => 1, "data" => ["Fenner, Martin", "Report"] }, + { "count" => 1, "data" => ["Fenner, Martin", "Service"] }, + { "count" => 34, "data" => ["Cousijn, Helena", "Text"] }, + { "count" => 1, "data" => ["Cousijn, Helena", "Audiovisual"] }, + { "count" => 1, "data" => ["Cousijn, Helena", "Output Management Plan"] }, + { "count" => 1, "data" => ["Cousijn, Helena", "Service"] }, + { "count" => 28, "data" => ["Dasler, Robin", "Text"] }, + { "count" => 1, "data" => ["Dasler, Robin", "Collection"] }, + { "count" => 27, "data" => ["Vierkant, Paul", "Text"] }, + { "count" => 1, "data" => ["Vierkant, Paul", "Other"] }, + { "count" => 1, "data" => ["Vierkant, Paul", "Report"] }, + { "count" => 21, "data" => ["Garza, Kristian", "Text"] }, + { "count" => 4, "data" => ["Garza, Kristian", "Software"] }, + { "count" => 2, "data" => ["Garza, Kristian", "Collection"] }, + { "count" => 1, "data" => ["Garza, Kristian", "Other"] } + ] + + + expect(flattened_contributors_works).to eq (expected_results) + end end diff --git a/spec/fixtures/files/contributor_worktype_multi_aggs.json b/spec/fixtures/files/contributor_worktype_multi_aggs.json new file mode 100644 index 000000000..640bb0f57 --- /dev/null +++ b/spec/fixtures/files/contributor_worktype_multi_aggs.json @@ -0,0 +1,305 @@ +[ + { + "key": "https://orcid.org/0000-0003-1419-2405", + "doc_count": 98, + "creators_and_contributors": { + "hits": { + "total": { + "value": 98, + "relation": "eq" + }, + "max_score": 18.399986, + "hits": [ + { + "_index": "dois_v2", + "_type": "_doc", + "_id": "10082554", + "_score": 18.399986, + "_ignored": [ + "landing_page.checked" + ], + "_source": { + "creators_and_contributors": [ + { + "name": "Fenner, Martin", + "nameIdentifiers": [ + { + "nameIdentifier": "https://orcid.org/0000-0003-1419-2405" + } + ] + } + ] + } + } + ] + } + }, + "work_types": { + "doc_count_error_upper_bound": 0, + "sum_other_doc_count": 0, + "buckets": [ + { + "key": "text:Text", + "doc_count": 75 + }, + { + "key": "software:Software", + "doc_count": 15 + }, + { + "key": "collection:Collection", + "doc_count": 4 + }, + { + "key": "computational-notebook:Computational Notebook", + "doc_count": 1 + }, + { + "key": "dataset:Dataset", + "doc_count": 1 + }, + { + "key": "report:Report", + "doc_count": 1 + }, + { + "key": "service:Service", + "doc_count": 1 + } + ] + } + }, + { + "key": "https://orcid.org/0000-0001-6660-6214", + "doc_count": 37, + "creators_and_contributors": { + "hits": { + "total": { + "value": 37, + "relation": "eq" + }, + "max_score": 18.399986, + "hits": [ + { + "_index": "dois_v2", + "_type": "_doc", + "_id": "17024242", + "_score": 18.399986, + "_ignored": [ + "landing_page.checked" + ], + "_source": { + "creators_and_contributors": [ + { + "name": "Cousijn, Helena", + "nameIdentifiers": [ + { + "nameIdentifier": "https://orcid.org/0000-0001-6660-6214" + } + ] + }, + { + "name": "Lowenberg, Daniella", + "nameIdentifiers": [ + { + "nameIdentifier": "https://orcid.org/0000-0003-2255-1869" + } + ] + } + ] + } + } + ] + } + }, + "work_types": { + "doc_count_error_upper_bound": 0, + "sum_other_doc_count": 0, + "buckets": [ + { + "key": "text:Text", + "doc_count": 34 + }, + { + "key": "audiovisual:Audiovisual", + "doc_count": 1 + }, + { + "key": "output-management-plan:Output Management Plan", + "doc_count": 1 + }, + { + "key": "service:Service", + "doc_count": 1 + } + ] + } + }, + { + "key": "https://orcid.org/0000-0002-4695-7874", + "doc_count": 29, + "creators_and_contributors": { + "hits": { + "total": { + "value": 29, + "relation": "eq" + }, + "max_score": 18.399986, + "hits": [ + { + "_index": "dois_v2", + "_type": "_doc", + "_id": "19717809", + "_score": 18.399986, + "_ignored": [ + "landing_page.checked" + ], + "_source": { + "creators_and_contributors": [ + { + "name": "Dasler, Robin", + "nameIdentifiers": [ + { + "nameIdentifier": "https://orcid.org/0000-0002-4695-7874" + } + ] + } + ] + } + } + ] + } + }, + "work_types": { + "doc_count_error_upper_bound": 0, + "sum_other_doc_count": 0, + "buckets": [ + { + "key": "text:Text", + "doc_count": 28 + }, + { + "key": "collection:Collection", + "doc_count": 1 + } + ] + } + }, + { + "key": "https://orcid.org/0000-0003-4448-3844", + "doc_count": 29, + "creators_and_contributors": { + "hits": { + "total": { + "value": 29, + "relation": "eq" + }, + "max_score": 18.399986, + "hits": [ + { + "_index": "dois_v2", + "_type": "_doc", + "_id": "50877604", + "_score": 18.399986, + "_source": { + "creators_and_contributors": [ + { + "name": "Vierkant, Paul", + "nameIdentifiers": [ + { + "nameIdentifier": "https://orcid.org/0000-0003-4448-3844" + } + ] + } + ] + } + } + ] + } + }, + "work_types": { + "doc_count_error_upper_bound": 0, + "sum_other_doc_count": 0, + "buckets": [ + { + "key": "text:Text", + "doc_count": 27 + }, + { + "key": "other:Other", + "doc_count": 1 + }, + { + "key": "report:Report", + "doc_count": 1 + } + ] + } + }, + { + "key": "https://orcid.org/0000-0003-3484-6875", + "doc_count": 28, + "creators_and_contributors": { + "hits": { + "total": { + "value": 28, + "relation": "eq" + }, + "max_score": 18.399986, + "hits": [ + { + "_index": "dois_v2", + "_type": "_doc", + "_id": "15175593", + "_score": 18.399986, + "_ignored": [ + "landing_page.checked" + ], + "_source": { + "creators_and_contributors": [ + { + "name": "Garza, Kristian", + "nameIdentifiers": [ + { + "nameIdentifier": "https://orcid.org/0000-0003-3484-6875" + } + ] + }, + { + "name": "Fenner, Martin", + "nameIdentifiers": [ + { + "nameIdentifier": "https://orcid.org/0000-0003-1419-2405" + } + ] + } + ] + } + } + ] + } + }, + "work_types": { + "doc_count_error_upper_bound": 0, + "sum_other_doc_count": 0, + "buckets": [ + { + "key": "text:Text", + "doc_count": 21 + }, + { + "key": "software:Software", + "doc_count": 4 + }, + { + "key": "collection:Collection", + "doc_count": 2 + }, + { + "key": "other:Other", + "doc_count": 1 + } + ] + } + } +] diff --git a/spec/graphql/types/work_type_spec.rb b/spec/graphql/types/work_type_spec.rb index 7032469e3..4c829bf52 100644 --- a/spec/graphql/types/work_type_spec.rb +++ b/spec/graphql/types/work_type_spec.rb @@ -1710,6 +1710,55 @@ expect(response.dig("data", "works", "authors").length()).to eq(1) expect(response.dig("data", "works", "creatorsAndContributors").length()).to eq(2) end + + it "returns the correct counts for the person_to_work_types multi-facet" do + gql_query = """ + query($first: Int, $cursor: String, $facetCount: Int) { + works(first: $first, after: $cursor, facetCount: $facetCount) { + totalCount + personToWorkTypesMultilevel { + id + title + count + inner { + id + title + count + } + } + } + } + """ + + response = LupoSchema.execute(gql_query).as_json + expect(response.dig("data", "works", "personToWorkTypesMultilevel").length()).to eq(2) + expect(response.dig( + "data", "works", "personToWorkTypesMultilevel", 0, "inner" + ).length()).to eq(1) + end + + it "returns the correct counts for the person_to_work_types flattened" do + gql_query = """ + query($first: Int, $cursor: String, $facetCount: Int) { + works(first: $first, after: $cursor, facetCount: $facetCount) { + totalCount + personToWorkTypesFlat{ + count + data + } + } + } + """ + + response = LupoSchema.execute(gql_query).as_json + expect(response.dig("data", "works", "personToWorkTypesFlat").length()).to eq(2) + expect(response.dig("data", "works", "personToWorkTypesFlat")).to eq( + [ + { "count" => 1, "data" => ["Garza, Kristian", "Dataset"] }, + { "count" => 1, "data" => ["Ross, Cody", "Dataset"] } + ] + ) + end end