Skip to content

Commit

Permalink
Merge pull request #560 from datacite/fix-pid-entity-facet
Browse files Browse the repository at this point in the history
Fix pid entity facet
  • Loading branch information
Martin Fenner authored Jun 5, 2020
2 parents 658f222 + 5c869e9 commit 6863850
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def facet_by_key(arr)

def facet_by_software(arr)
arr.map do |hsh|
{ "id" => hsh["key"].downcase,
{ "id" => hsh["key"].parameterize(separator: '_'),
"title" => hsh["key"],
"count" => hsh["doc_count"] }
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def facet_by_resource_type(arr)

def facet_by_software(arr)
arr.map do |hsh|
{ "id" => hsh["key"].downcase,
{ "id" => hsh["key"].parameterize(separator: '_'),
"title" => hsh["key"],
"count" => hsh["doc_count"] }
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/service_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def affiliations
end

def pid_entities
object.total_count.positive? ? facet_by_combined_key(object.aggregations.pid_entities.subject.buckets) : []
object.total_count.positive? ? facet_by_software(object.aggregations.pid_entities.subject.buckets) : []
end

def fields_of_science
Expand Down
4 changes: 2 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,11 @@ def self.query(query, options={})
filter << { terms: { "subjects.subject": options[:subject].split(",") } } if options[:subject].present?
if options[:pid_entity].present?
filter << { term: { "subjects.subjectScheme": "PidEntity" } }
filter << { terms: { "subjects.subject": options[:pid_entity].split(",") } }
filter << { terms: { "subjects.subject": options[:pid_entity].split(",").map(&:humanize) } }
end
if options[:field_of_science].present?
filter << { term: { "subjects.subjectScheme": "Fields of Science and Technology (FOS)" } }
filter << { term: { "subjects.subject": "FOS: " + options[:field_of_science].humanize } }
filter << { terms: { "subjects.subject": "FOS: " + options[:field_of_science].split(",").map(&:humanize) } }
end
filter << { term: { source: options[:source] } } if options[:source].present?
filter << { range: { reference_count: { "gte": options[:has_references].to_i } } } if options[:has_references].present?
Expand Down
13 changes: 9 additions & 4 deletions spec/graphql/types/service_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,25 @@

let(:query) do
%(query {
services(pidEntity: "Instrument") {
services(pidEntity: "instrument") {
totalCount
pageInfo {
endCursor
hasNextPage
}
years {
id
title
count
}
pidEntities {
id
title
count
}
fieldsOfScience {
id
title
count
}
nodes {
Expand Down Expand Up @@ -77,11 +80,13 @@
response = LupoSchema.execute(query).as_json

expect(response.dig("data", "services", "totalCount")).to eq(3)
expect(response.dig("data", "services", "pidEntities")).to eq([{"id"=>"Instrument", "count"=>3}])
expect(response.dig("data", "services", "fieldsOfScience")).to eq([{"count"=>3, "id"=>"computer_and_information_sciences"}])
expect(response.dig("data", "services", "pidEntities")).to eq([{"count"=>3, "id"=>"instrument", "title"=>"Instrument"}])
expect(response.dig("data", "services", "fieldsOfScience")).to eq([{"count"=>3,
"id"=>"computer_and_information_sciences",
"title"=>"Computer and information sciences"}])
expect(Base64.urlsafe_decode64(response.dig("data", "services", "pageInfo", "endCursor")).split(",", 2).last).to eq(services.last.uid)
expect(response.dig("data", "services", "pageInfo", "hasNextPage")).to be false
expect(response.dig("data", "services", "years")).to eq([{"count"=>3, "id"=>"2011"}])
expect(response.dig("data", "services", "years")).to eq([{"count"=>3, "id"=>"2011", "title"=>"2011"}])
expect(response.dig("data", "services", "nodes").length).to eq(3)

service = response.dig("data", "services", "nodes", 0)
Expand Down

0 comments on commit 6863850

Please sign in to comment.