Skip to content

Commit

Permalink
Merge pull request #1315 from datacite/facet-license-missing
Browse files Browse the repository at this point in the history
Facet license missing
  • Loading branch information
jrhoads authored Jan 15, 2025
2 parents 59776af + 860aa67 commit b8bdba0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
21 changes: 9 additions & 12 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ def facet_by_license(arr)
end
end

def facet_by_license_and_other(aggregate)
if aggregate
arr = facet_by_license(aggregate.buckets)
add_other(arr, aggregate.sum_other_doc_count)
else
[]
end
end

def facet_by_schema(arr)
arr.map do |hsh|
id = hsh["key"].split("-").last
Expand Down Expand Up @@ -552,17 +561,5 @@ def add_other(arr, other_count)

arr
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
4 changes: 3 additions & 1 deletion app/controllers/datacite_dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def index
prefixes: :facet_by_key,
certificates: :facet_by_key,
licenses: :facet_by_license,
licenses_with_missing: :facet_by_license_and_other,
schema_versions: :facet_by_schema,
link_checks_status: :facet_by_cumulative_year,
creators_and_contributors: :facet_by_creators_and_contributors,
Expand All @@ -249,7 +250,8 @@ def index
}

facets_to_bucket_path = {
fields_of_science: [:subject, :buckets]
fields_of_science: [:subject, :buckets],
licenses_with_missing: [],
}

aggregations = response.aggregations
Expand Down
1 change: 1 addition & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ def as_indexed_json(_options = {})
},
},
licenses: { terms: { field: "rights_list.rightsIdentifier", size: 10, min_doc_count: 1 } },
licenses_with_missing: { terms: { field: "rights_list.rightsIdentifier", size: 10, min_doc_count: 1, missing: "__missing__" } },
languages: { terms: { field: "language", size: 10, min_doc_count: 1 } },
certificates: { terms: { field: "client.certificate", size: 10, min_doc_count: 1 } },
creators_and_contributors: {
Expand Down
22 changes: 22 additions & 0 deletions spec/requests/datacite_dois/datacite_dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1626,4 +1626,26 @@ def clear_doi_index
expect(json["errors"]).to eq([{ "status" => "401", "title" => "Bad credentials." }])
end
end

describe "GET /dois search with license values", prefix_pool_size: 1 do
let!(:dois) { create_list(:doi, 10, client: client, aasm_state: "findable") }
let!(:dois_missing_license) do
create_list(:doi, 3, client: client, aasm_state: "findable",
rights_list: [{ "rightsIdentifier" => "" }]
)
end

before do
clear_doi_index
import_doi_index
end

it "returns license values with missing when flag is set" do
get "/dois?facets=licenses_with_missing", nil, headers

expect(last_response.status).to eq(200)
expect(json.dig("meta", "licensesWithMissing")).to be_truthy
expect(json.dig("meta", "licensesWithMissing", 1, "id")).to eq("__missing__")
end
end
end

0 comments on commit b8bdba0

Please sign in to comment.