Skip to content

Commit

Permalink
enable search by multiple dois
Browse files Browse the repository at this point in the history
necesary for citations
  • Loading branch information
kjgarza committed Apr 8, 2019
1 parent 4c02825 commit d7cabfc
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d7cabfc

Please sign in to comment.