From d7cabfcaf94e482779f71e09b6293b06a4c28d29 Mon Sep 17 00:00:00 2001 From: Kristian Garza Date: Mon, 8 Apr 2019 18:04:53 +0200 Subject: [PATCH] enable search by multiple dois necesary for citations --- app/models/doi.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/models/doi.rb b/app/models/doi.rb index cd8e823bc..537a20dd0 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -711,6 +711,32 @@ def media_ids media.pluck(:id).map { |m| Base32::URL.encode(m, split: 4, length: 16) }.compact end + + def self.normalize_doi(doi) + doi = Array(/\A(?:(http|https):\/(\/)?(dx\.)?(doi.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match(doi)).last + doi = doi.delete("\u200B").downcase if doi.present? + "https://doi.org/#{doi}" if doi.present? + end + + def self.find_by_ids(ids, options={}) + dois = ids.split(",").map(&:upcase) + + + puts dois + + __elasticsearch__.search({ + from: 0, + size: 1000, + sort: [{ created: { order: 'asc' }}], + query: { + terms: { + doi: dois + } + }, + aggregations: query_aggregations + }) + end + def xml_encoded Base64.strict_encode64(xml) if xml.present? rescue ArgumentError => exception