-
Notifications
You must be signed in to change notification settings - Fork 0
/
solr_document_decorator.rb
179 lines (167 loc) · 7.45 KB
/
solr_document_decorator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# frozen_string_literal: true
module AdlSolrDocumentDecorator
extend ActiveSupport::Concern
class_methods do
def attribute(name, type, field)
define_method name do
type.coerce(self[field])
end
end
def solr_name(*args)
ActiveFedora.index_field_mapper.solr_name(*args)
end
end
module Solr
class Array
# @return [Array]
def self.coerce(input)
::Array.wrap(input)
end
end
class String
# @return [String]
def self.coerce(input)
::Array.wrap(input).first
end
end
class Date
# @return [Date]
def self.coerce(input)
field = String.coerce(input)
return if field.blank?
begin
::Date.parse(field)
rescue ArgumentError
Rails.logger.info "Unable to parse date: #{field.first.inspect}"
end
end
end
end
# Keep these alphebetized; comments indicate those in basic_metadata
# see https://github.com/samvera/hyrax/blob/master/app/models/concerns/hyrax/solr_document/metadata.rb
included do
attribute :abstract, Solr::Array, solr_name('abstract')
attribute :access_provided_by, Solr::Array, solr_name('access_provided_by')
attribute :advisor, Solr::Array, solr_name('advisor')
attribute :alt, Solr::Array, solr_name('alt')
attribute :awarding_institution, Solr::Array, solr_name('awarding_institution')
# based_near and based_near
attribute :content_version, Solr::Array, solr_name('content_version')
# contributor
# creator
attribute :date, Solr::Array, solr_name('date')
attribute :date_accepted, Solr::Array, solr_name('date_accepted')
attribute :date_available, Solr::Array, solr_name('date_available')
attribute :date_collected, Solr::Array, solr_name('date_collected')
attribute :date_copyrighted, Solr::Array, solr_name('date_copyrighted')
attribute :date_issued, Solr::Array, solr_name('date_issued')
# date_created
attribute :date_of_award, Solr::Array, solr_name('date_of_award')
attribute :date_published, Solr::Array, solr_name('date_published')
attribute :date_submitted, Solr::Array, solr_name('date_submitted')
attribute :date_updated, Solr::Array, solr_name('date_updated')
attribute :date_valid, Solr::Array, solr_name('date_valid')
attribute :dc_access_rights, Solr::Array, solr_name('dc_access_rights')
attribute :department, Solr::Array, solr_name('department')
# description
attribute :doi, Solr::Array, solr_name('doi')
attribute :edition, Solr::Array, solr_name('edition')
attribute :editor, Solr::Array, solr_name('editor')
attribute :end_date, Solr::Array, solr_name('end_date')
attribute :event_date, Solr::Array, solr_name('event_date')
attribute :extent, Solr::Array, solr_name('extent')
attribute :dc_format, Solr::Array, solr_name('dc_format')
attribute :former_identifier, Solr::Array, solr_name('former_identifier')
attribute :funder, Solr::Array, solr_name('funder')
attribute :resource_type_general, Solr::Array, solr_name('resource_type_general')
attribute :has_restriction, Solr::Array, solr_name('has_restriction')
# rubocop:enable Naming/PredicateName
# identifier
attribute :isbn, Solr::Array, solr_name('isbn')
attribute :issue_number, Solr::Array, solr_name('issue_number')
# keyword
# language
attribute :last_access, Solr::Array, solr_name('last_access')
attribute :lat, Solr::Array, solr_name('lat')
# license
attribute :location, Solr::Array, solr_name('location')
attribute :long, Solr::Array, solr_name('long')
attribute :managing_organisation, Solr::Array, solr_name('managing_organisation')
attribute :module_code, Solr::Array, solr_name('module_code')
attribute :note, Solr::Array, solr_name('note')
attribute :number_of_downloads, Solr::Array, solr_name('last_access')
attribute :official_url, Solr::Array, solr_name('official_url')
attribute :output_of, Solr::Array, solr_name('output_of')
attribute :official_url, Solr::Array, solr_name('official_url')
attribute :packaged_by_ids, Solr::Array, solr_name('packaged_by_ids', :symbol)
attribute :package_ids, Solr::Array, solr_name('package_ids', :symbol)
attribute :pagination, Solr::Array, solr_name('pagination')
attribute :part, Solr::Array, solr_name('part')
attribute :place_of_publication, Solr::Array, solr_name('place_of_publication')
attribute :presented_at, Solr::Array, solr_name('presented_at')
attribute :part_of, Solr::Array, solr_name('part_of')
attribute :project, Solr::Array, solr_name('project')
attribute :publication_status, Solr::Array, solr_name('publication_status')
# publisher
attribute :qualification_level, Solr::Array, solr_name('qualification_level')
attribute :qualification_name, Solr::Array, solr_name('qualification_name')
attribute :refereed, Solr::Array, solr_name('refereed')
attribute :related_url, Solr::Array, solr_name('related_url')
# resource_type
# rights_statement
attribute :series, Solr::Array, solr_name('series')
# source
attribute :start_date, Solr::Array, solr_name('start_date')
# subject
attribute :subtitle, Solr::Array, solr_name('subtitle')
attribute :volume_number, Solr::Array, solr_name('volume_number')
# archivematica
attribute :aip_uuid, Solr::Array, solr_name('aip_uuid')
attribute :transfer_uuid, Solr::Array, solr_name('transfer_uuid')
attribute :sip_uuid, Solr::Array, solr_name('sip_uuid')
attribute :dip_uuid, Solr::Array, solr_name('dip_uuid')
attribute :aip_status, Solr::Array, solr_name('aip_status')
attribute :dip_status, Solr::Array, solr_name('dip_status')
attribute :aip_size, Solr::Array, solr_name('aip_size')
attribute :dip_size, Solr::Array, solr_name('dip_size')
attribute :aip_current_path, Solr::Array, solr_name('aip_current_path')
attribute :dip_current_path, Solr::Array, solr_name('dip_current_path')
attribute :aip_current_location, Solr::Array, solr_name('aip_current_location')
attribute :dip_current_location, Solr::Array, solr_name('dip_current_location')
attribute :aip_resource_uri, Solr::Array, solr_name('aip_resource_uri')
attribute :dip_resource_uri, Solr::Array, solr_name('dip_resource_uri')
attribute :origin_pipeline, Solr::Array, solr_name('origin_pipeline')
attribute :slug, Solr::String, 'slug_tesim'
attribute :fedora_id, Solr::String, 'fedora_id_ssi'
attribute :aark_id, Solr::String, 'aark_id_tesim'
attribute :bibliographic_citation, Solr::String, 'bibliographic_citation_tesim'
attribute :alt, Solr::String, 'alt_tesim'
attribute :file_set_ids, Solr::Array, 'file_set_ids_ssim'
attribute :video_embed, Solr::String, 'video_embed_tesim'
field_semantics.merge!(
contributor: 'contributor_tesim',
creator: 'creator_tesim',
date: 'date_created_tesim',
description: 'description_tesim',
identifier: 'aark_id_tesim',
language: 'language_tesim',
publisher: 'publisher_tesim',
relation: 'nesting_collection__pathnames_ssim',
related_url: 'related_url_tesim',
rights: 'rights_statement_tesim',
subject: 'subject_tesim',
title: 'title_tesim',
type: 'human_readable_type_tesim'
)
end
def to_param
slug || id.to_s
end
def thumbnail_url
Addressable::URI.parse("https://#{Site.account.cname}#{thumbnail_path}").to_s
end
def remote_url
self['remote_url_tesim']
end
end
SolrDocument.include(AdlSolrDocumentDecorator)