Skip to content

Commit

Permalink
Revert "Merge pull request #965 from datacite/fair-vis-feature-6"
Browse files Browse the repository at this point in the history
This reverts commit 6e71b5d, reversing
changes made to 2cc956e.
  • Loading branch information
richardhallett committed Jun 2, 2023
1 parent 399a168 commit 6d8b885
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 158 deletions.
19 changes: 1 addition & 18 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ module Facetable
"mit" => "MIT",
"mpl-2.0" => "MPL-2.0",
"ogl-canada-2.0" => "OGL-Canada-2.0",
"__missing__" => "Missing",
}.freeze

LOWER_BOUND_YEAR = 2_010
Expand All @@ -80,8 +79,6 @@ module Facetable
"igsnCatalog" => "IGSN ID Catalog"
}.freeze

OTHER = { "__other__" => "Other", "__missing__" => "Missing" }.freeze

included do
def facet_by_key_as_string(arr)
arr.map do |hsh|
Expand Down Expand Up @@ -446,9 +443,7 @@ def clients_totals(arr)
def facet_by_combined_key(arr)
arr.map do |hsh|
id, title = hsh["key"].split(":", 2)
if id == "__missing__"
title = OTHER["__missing__"]
end

{ "id" => id, "title" => title, "count" => hsh["doc_count"] }
end
end
Expand Down Expand Up @@ -494,17 +489,5 @@ def facet_by_authors(arr)
end
}.compact
end

def add_other(arr, other_count)
if other_count > 0
arr << {
"id" => "__other__",
"title" => OTHER["__other__"],
"count" => other_count,
}
end

arr
end
end
end
6 changes: 2 additions & 4 deletions app/graphql/types/interfaces/work_facets_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def repositories

def affiliations
if object.aggregations.affiliations
arr = facet_by_combined_key(object.aggregations.affiliations.buckets)
add_other(arr, object.aggregations.affiliations.sum_other_doc_count)
facet_by_combined_key(object.aggregations.affiliations.buckets)
else
[]
end
Expand All @@ -75,8 +74,7 @@ def authors

def licenses
if object.aggregations.licenses
arr = facet_by_license(object.aggregations.licenses.buckets)
add_other(arr, object.aggregations.licenses.sum_other_doc_count)
facet_by_license(object.aggregations.licenses.buckets)
else
[]
end
Expand Down
3 changes: 1 addition & 2 deletions app/graphql/types/work_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def total_open_licenses

def resource_types
if object.aggregations.resource_types
arr = facet_by_combined_key(object.aggregations.resource_types.buckets)
add_other(arr, object.aggregations.resource_types.sum_other_doc_count)
facet_by_combined_key(object.aggregations.resource_types.buckets)
else
[]
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def as_indexed_json(_options = {})
def self.gql_query_aggregations(facet_count: 10)
if facet_count.positive?
{
resource_types: { terms: { field: "resource_type_id_and_name", size: facet_count, min_doc_count: 1, missing: "__missing__" } },
resource_types: { terms: { field: "resource_type_id_and_name", size: facet_count, min_doc_count: 1 } },
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"] } },
Expand All @@ -636,7 +636,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__" } },
affiliations: { terms: { field: "affiliation_id_and_name", size: facet_count, min_doc_count: 1 } },
authors: {
terms: { field: "creators.nameIdentifiers.nameIdentifier", size: facet_count, min_doc_count: 1 },
aggs: {
Expand Down Expand Up @@ -670,7 +670,7 @@ def self.gql_query_aggregations(facet_count: 10)
fields_of_science_repository: {
terms: { field: "fields_of_science_repository", size: facet_count, min_doc_count: 1 }
},
licenses: { terms: { field: "rights_list.rightsIdentifier", size: facet_count, min_doc_count: 1, missing: "__missing__" } },
licenses: { terms: { field: "rights_list.rightsIdentifier", size: facet_count, min_doc_count: 1 } },
languages: { terms: { field: "language", size: facet_count, min_doc_count: 1 } },
view_count: { sum: { field: "view_count" } },
download_count: { sum: { field: "download_count" } },
Expand Down
131 changes: 0 additions & 131 deletions spec/graphql/types/work_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1345,135 +1345,4 @@
)
end
end

describe "query fields with __other__ and __missing__ data", elasticsearch: true do
let(:query) do
"query($first: Int, $cursor: String, $facetCount: Int) {
works(first: $first, after: $cursor, facetCount: $facetCount) {
totalCount
resourceTypes {
id
title
count
}
affiliations {
id
title
count
}
licenses {
id
title
count
}
}
}"
end

let!(:works_5) do
create_list(:doi, 5, aasm_state: "findable",
types: { "resourceTypeGeneral" => "Text" },
creators: [{
affiliation: [{
"name": "5",
"affiliationIdentifier": "https://ror.org/5",
"affiliationIdentifierScheme": "ROR",
}],
}],
rights_list: [{ "rightsIdentifier" => "cc-by-1.0" }]
)
end
let!(:works_4) do
create_list(:doi, 4, aasm_state: "findable",
types: { "resourceTypeGeneral" => "JournalArticle" },
creators: [{
affiliation: [{
"name": "4",
"affiliationIdentifier": "https://ror.org/4",
"affiliationIdentifierScheme": "ROR",
}],
}],
rights_list: [{ "rightsIdentifier" => "cc-by-2.0" }]
)
end
let!(:works_3) do
create_list(:doi, 3, aasm_state: "findable",
types: { "resourceTypeGeneral" => "Image" },
creators: [{
affiliation: [{
"name": "3",
"affiliationIdentifier": "https://ror.org/3",
"affiliationIdentifierScheme": "ROR",
}],
}],
rights_list: [{ "rightsIdentifier" => "cc-by-2.5" }]
)
end
let!(:works_2) do
create_list(:doi, 2, aasm_state: "findable",
types: { "resourceTypeGeneral" => "PhysicalObject" },
creators: [{
affiliation: [{
"name": "2",
"affiliationIdentifier": "https://ror.org/2",
"affiliationIdentifierScheme": "ROR",
}],
}],
rights_list: [{ "rightsIdentifier" => "cc-by-3.0" }]
)
end
let!(:works_other) do
create(:doi, aasm_state: "findable",
types: { "resourceTypeGeneral" => "Preprint" },
creators: [{
affiliation: [
{
"name": "1",
"affiliationIdentifier": "https://ror.org/1",
"affiliationIdentifierScheme": "ROR",
},
{
"name": "0",
"affiliationIdentifier": "https://ror.org/0",
"affiliationIdentifierScheme": "ROR",
}
],
}],
rights_list: [
{ "rightsIdentifier" => "bsd-2-clause" },
{ "rightsIdentifier" => "bsd-3-clause" },
])
end
let!(:missing) do
create_list(:doi, 3, aasm_state: "findable",
creators: [{ affiliation: [] }],
rights_list: [])
end

before do
Doi.import
sleep 2
@works = Doi.gql_query(nil, page: { cursor: [], size: 11 }).results.to_a
end

it "returns all works" do
response =
LupoSchema.execute(
query,
variables: { first: 4, cursor: nil, facetCount: 5 }
).
as_json

expect(response.dig("data", "works", "totalCount")).to eq(18)
expect(response.dig("data", "works", "resourceTypes")).to eq(
[{ "count" => 5, "id" => "text", "title" => "Text" }, { "count" => 4, "id" => "journal-article", "title" => "Journal Article" }, { "count" => 3, "id" => "dataset", "title" => "Dataset" }, { "count" => 3, "id" => "image", "title" => "Image" }, { "count" => 2, "id" => "physical-object", "title" => "Physical Object" }, { "count" => 1, "id" => "__other__", "title" => "Other" }]
)
expect(response.dig("data", "works", "affiliations")).to eq(
[{ "count" => 5, "id" => "ror.org/5", "title" => "5" }, { "count" => 4, "id" => "ror.org/4", "title" => "4" }, { "count" => 3, "id" => "__missing__", "title" => "Missing" }, { "count" => 3, "id" => "ror.org/3", "title" => "3" }, { "count" => 2, "id" => "ror.org/2", "title" => "2" }, { "count" => 2, "id" => "__other__", "title" => "Other" }]
)
expect(response.dig("data", "works", "licenses")).to eq(
[{ "count" => 5, "id" => "cc-by-1.0", "title" => "CC-BY-1.0" }, { "count" => 4, "id" => "cc-by-2.0", "title" => "CC-BY-2.0" }, { "count" => 3, "id" => "__missing__", "title" => "Missing" }, { "count" => 3, "id" => "cc-by-2.5", "title" => "CC-BY-2.5" }, { "count" => 2, "id" => "cc-by-3.0", "title" => "CC-BY-3.0" }, { "count" => 2, "id" => "__other__", "title" => "Other" }]
)
end
end
end

0 comments on commit 6d8b885

Please sign in to comment.