From a094bea92214c773f848bc5522069281a61bd51b Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 18 Feb 2020 07:35:28 +0100 Subject: [PATCH] Update doi.rb `ElasticsearchLoader` is mostly broken due the changes in the DOI model https://github.com/datacite/lupo/commit/1de1af62614565ee52857a7cd8ee92922cc3aae4 addresses: https://github.com/datacite/lupo/issues/419 --- app/models/doi.rb | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/app/models/doi.rb b/app/models/doi.rb index cd7d7011c..f9b69a7e3 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -597,15 +597,31 @@ 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 doi - def self.find_by_id(id) - __elasticsearch__.search( + # return results for one or more ids + def self.find_by_id(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: { - match: { - uid: id, - }, + bool: { + must: must, + } }, - ) + aggregations: query_aggregations, + }) end def self.query(query, options={})