Skip to content

Commit

Permalink
create and index date published. datacite/blog#122
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 9, 2019
1 parent 96a6c2c commit 5036c3b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def index
when "-created" then { created: { order: 'desc' }}
when "updated" then { updated: { order: 'asc' }}
when "-updated" then { updated: { order: 'desc' }}
when "published" then { published: { order: 'asc' }}
when "-published" then { published: { order: 'desc' }}
when "relevance" then { "_score": { "order": "desc" }}
else { updated: { order: 'desc' }}
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class Doi < ActiveRecord::Base
}
indexes :cache_key, type: :keyword
indexes :registered, type: :date, ignore_malformed: true
indexes :published, type: :date, ignore_malformed: true
indexes :created, type: :date, ignore_malformed: true
indexes :updated, type: :date, ignore_malformed: true

Expand Down Expand Up @@ -300,6 +301,7 @@ def as_indexed_json(options={})
"registered" => registered,
"created" => created,
"updated" => updated,
"published" => published,
"client" => client.as_indexed_json,
"provider" => provider.as_indexed_json,
"resource_type" => resource_type.try(:as_indexed_json),
Expand Down Expand Up @@ -850,6 +852,10 @@ def date_updated
updated
end

def published
get_date(dates, "issued") || publication_year.to_s
end

def cache_key
timestamp = updated || Time.zone.now
"dois/#{uid}-#{timestamp.iso8601}"
Expand Down
6 changes: 5 additions & 1 deletion app/serializers/doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DoiSerializer
set_id :uid
# don't cache dois, as works are cached using the doi model

attributes :doi, :prefix, :suffix, :identifiers, :creators, :titles, :publisher, :container, :publication_year, :subjects, :contributors, :dates, :language, :types, :related_identifiers, :sizes, :formats, :version, :rights_list, :descriptions, :geo_locations, :funding_references, :xml, :url, :content_url, :metadata_version, :schema_version, :source, :is_active, :state, :reason, :landing_page, :created, :registered, :updated
attributes :doi, :prefix, :suffix, :identifiers, :creators, :titles, :publisher, :container, :publication_year, :subjects, :contributors, :dates, :language, :types, :related_identifiers, :sizes, :formats, :version, :rights_list, :descriptions, :geo_locations, :funding_references, :xml, :url, :content_url, :metadata_version, :schema_version, :source, :is_active, :state, :reason, :landing_page, :created, :registered, :published, :updated
attributes :prefix, :suffix, if: Proc.new { |object, params| params && params[:detail] }

belongs_to :client, record_type: :clients
Expand All @@ -27,6 +27,10 @@ class DoiSerializer
object.version_info
end

attribute :published do |object|
object.respond_to?(:published) ? :published : nil
end

attribute :is_active do |object|
object.is_active.to_s.getbyte(0) == 1 ? true : false
end
Expand Down

0 comments on commit 5036c3b

Please sign in to comment.