Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/datacite/lupo
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 19, 2020
2 parents dc01303 + 2ce9d90 commit da2965c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def index
if params[:id].present?
response = Doi.find_by_id(params[:id])
elsif params[:ids].present?
response = Doi.find_by_id(params[:ids], page: page, sort: sort)
response = Doi.find_by_ids(params[:ids], page: page, sort: sort)
else
response = Doi.query(params[:query],
state: params[:state],
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def index
if params[:id].present?
response = Doi.find_by_id(params[:id])
elsif params[:ids].present?
response = Doi.find_by_id(params[:ids], page: page, sort: sort)
response = Doi.find_by_ids(params[:ids], page: page, sort: sort)
else
response = Doi.query(params[:query],
exclude_registration_agencies: true,
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/elasticsearch_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(model)
end

def perform(ids)
@model.find_by_id(ids).results.each { |record| fulfill(record.uid, record) }
@model.find_by_ids(ids).results.each { |record| fulfill(record.uid, record) }
ids.each { |id| fulfill(id, nil) unless fulfilled?(id) }
end
end
2 changes: 1 addition & 1 deletion app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def people(query: nil, first: nil)
def creative_works(query: nil, ids: nil, client_id: nil, provider_id: nil, first: nil)
if ids.present?
dois = ids.split(",").map { |i| doi_from_url(i) }
Doi.find_by_id(dois, page: { number: 1, size: first }).results.to_a
Doi.find_by_ids(dois, page: { number: 1, size: first }).results.to_a
else
Doi.query(query, client_id: client_id, provider_id: provider_id, state: "findable", page: { number: 1, size: first }).results.to_a
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/batch_loader_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module BatchLoaderHelper
def load_doi(object)
BatchLoader.for(object.uuid).batch do |dois, loader|
dois = object.doi
results = Doi.find_by_id(dois).results
results = Doi.find_by_ids(dois).results
loader.call(object.uuid, results)
end
end
Expand Down
27 changes: 27 additions & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,33 @@ def self.query_fields
["uid^50", "related_identifiers.relatedIdentifier^3", "funding_references.relatedIdentifier^3", "container.identifier^3", 'titles.title^3', 'creator_names^3', 'creators.name^3', 'creators.id^3', 'publisher^3', 'descriptions.description^3', 'types.resourceTypeGeneral^3', 'subjects.subject^3', 'client.uid^3', 'provider.uid^3', '_all']
end

# return results for one or more ids
def self.find_by_ids(ids, options={})
ids = ids.split(",") if ids.is_a?(String)

options[:page] ||= {}
options[:page][:number] ||= 1
options[:page][:size] ||= 1000
options[:sort] ||= { created: { order: "asc" }}

must = [{ terms: { doi: ids.map(&:upcase) }}]
must << { terms: { aasm_state: options[:state].to_s.split(",") }} if options[:state].present?
must << { terms: { provider_id: options[:provider_id].split(",") }} if options[:provider_id].present?
must << { terms: { client_id: options[:client_id].to_s.split(",") }} if options[:client_id].present?

__elasticsearch__.search({
from: (options.dig(:page, :number) - 1) * options.dig(:page, :size),
size: options.dig(:page, :size),
sort: [options[:sort]],
query: {
bool: {
must: must,
}
},
aggregations: query_aggregations,
})
end

# return results for one doi
def self.find_by_id(id)
__elasticsearch__.search(
Expand Down

0 comments on commit da2965c

Please sign in to comment.