Module: Hyrax::SolrDocumentBehavior

Extended by:
ActiveSupport::Concern
Includes:
Hydra::Works::MimeTypes, Permissions::Readable, Hyrax::SolrDocument::Characterization, Hyrax::SolrDocument::Export
Defined in:
app/models/concerns/hyrax/solr_document_behavior.rb

Defined Under Namespace

Classes: ModelWrapper

Instance Method Summary collapse

Methods included from Hyrax::SolrDocument::Characterization

#byte_order, #capture_device, #color_map, #color_space, #compression, #duration, #file_size, #file_title, #filename, #format_label, #gps_timestamp, #height, #image_producer, #last_modified, #latitude, #longitude, #orientation, #original_checksum, #page_count, #profile_name, #profile_version, #sample_rate, #scanning_software, #well_formed, #width

Methods included from Hyrax::SolrDocument::Export

#end_note_format, #endnote_filename, #export_as_endnote, #persistent_url

Methods included from Permissions::Readable

#private?, #public?, #registered?

Instance Method Details

#admin_setObject



221
222
223
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 221

def admin_set
  fetch(Solrizer.solr_name('admin_set'), [])
end

#based_nearObject



197
198
199
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 197

def based_near
  self[Solrizer.solr_name('based_near')]
end

#collection?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 63

def collection?
  hydra_model == ::Collection
end

#collection_idsObject



217
218
219
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 217

def collection_ids
  fetch('collection_ids_tesim', [])
end

#collectionsObject

Find the solr documents for the collections this object belongs to TODO: can we remove this method now?



227
228
229
230
231
232
233
234
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 227

def collections
  return @collections if @collections
  query = 'id:' + collection_ids.map { |id| '"' + id + '"' }.join(' OR ')
  result = Blacklight.default_index.connection.select(params: { q: query })
  @collections = result['response']['docs'].map do |hash|
    ::SolrDocument.new(hash)
  end
end

#contributorObject



122
123
124
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 122

def contributor
  fetch(Solrizer.solr_name('contributor'), [])
end

#create_dateObject



189
190
191
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 189

def create_date
  date_field('system_create')
end

#creatorObject



117
118
119
120
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 117

def creator
  descriptor = hydra_model.index_config[:creator].behaviors.first
  fetch(Solrizer.solr_name('creator', descriptor), [])
end

#date_createdObject

Date created indexed as a string. This allows users to enter values like: ‘Circa 1840-1844’



185
186
187
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 185

def date_created
  fetch(Solrizer.solr_name("date_created"), [])
end

#date_modifiedObject



88
89
90
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 88

def date_modified
  date_field('date_modified')
end

#date_uploadedObject



92
93
94
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 92

def date_uploaded
  date_field('date_uploaded')
end

#depositor(default = '') ⇒ Object



96
97
98
99
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 96

def depositor(default = '')
  val = first(Solrizer.solr_name('depositor'))
  val.present? ? val : default
end

#descriptionObject



105
106
107
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 105

def description
  fetch(Solrizer.solr_name('description'), [])
end

#edit_groupsObject



209
210
211
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 209

def edit_groups
  fetch(::Ability.edit_group_field, [])
end

#edit_peopleObject



213
214
215
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 213

def edit_people
  fetch(::Ability.edit_user_field, [])
end

#embargo_release_dateObject



142
143
144
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 142

def embargo_release_date
  self[Hydra.config.permissions.embargo.release_date]
end

#file_formatObject



113
114
115
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 113

def file_format
  first(Solrizer.solr_name('file_format'))
end

#human_readable_typeObject



76
77
78
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 76

def human_readable_type
  first(Solrizer.solr_name('human_readable_type', :stored_searchable))
end

#hydra_modelObject

Method to return the ActiveFedora model



72
73
74
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 72

def hydra_model
  first(Solrizer.solr_name('has_model', :symbol)).constantize
end

#identifierObject



193
194
195
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 193

def identifier
  self[Solrizer.solr_name('identifier')]
end

#itemtypeObject

Add a schema.org itemtype



11
12
13
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 11

def itemtype
  ResourceTypesService.microdata_type(resource_type.first)
end

#keywordObject



138
139
140
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 138

def keyword
  fetch(Solrizer.solr_name('keyword'), [])
end

#labelObject



109
110
111
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 109

def label
  first(Solrizer.solr_name('label'))
end

#languageObject



134
135
136
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 134

def language
  fetch(Solrizer.solr_name('language'), [])
end

#lease_expiration_dateObject



146
147
148
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 146

def lease_expiration_date
  self[Hydra.config.permissions.lease.expiration_date]
end

#member_of_collection_idsObject



236
237
238
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 236

def member_of_collection_ids
  fetch(Solrizer.solr_name('member_of_collection_ids', :symbol), [])
end

#mime_typeObject



154
155
156
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 154

def mime_type
  self[Solrizer.solr_name('mime_type', :stored_sortable)]
end

#publisherObject



130
131
132
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 130

def publisher
  fetch(Solrizer.solr_name('publisher'), [])
end

#read_groupsObject



158
159
160
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 158

def read_groups
  fetch(::Ability.read_group_field, [])
end


201
202
203
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 201

def related_url
  self[Solrizer.solr_name('related_url')]
end

#representative_idObject



80
81
82
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 80

def representative_id
  first(Solrizer.solr_name('hasRelatedMediaFragment', :symbol))
end

#resource_typeObject



205
206
207
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 205

def resource_type
  fetch(Solrizer.solr_name("resource_type"), [])
end

#rightsObject



150
151
152
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 150

def rights
  fetch(Solrizer.solr_name('rights'), [])
end

#sourceObject



162
163
164
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 162

def source
  fetch(Solrizer.solr_name('source'), [])
end

#subjectObject



126
127
128
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 126

def subject
  fetch(Solrizer.solr_name('subject'), [])
end

#suppressed?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 67

def suppressed?
  first(Solrizer.solr_name('suppressed', stored_boolean_field))
end

#thumbnail_idObject



84
85
86
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 84

def thumbnail_id
  first(Solrizer.solr_name('hasRelatedImage', :symbol))
end

#titleObject



101
102
103
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 101

def title
  fetch(Solrizer.solr_name('title'), [])
end

#title_or_labelObject



15
16
17
18
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 15

def title_or_label
  return label if title.blank?
  title.join(', ')
end

#to_modelObject

Offer the source (ActiveFedora-based) model to Rails for some of the Rails methods (e.g. link_to).

Examples:

link_to '...', SolrDocument(:id => 'bXXXXXX5').new => <a href="/dams_object/bXXXXXX5">...</a>


59
60
61
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 59

def to_model
  @model ||= ModelWrapper.new(hydra_model, id)
end

#to_paramObject



20
21
22
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 20

def to_param
  id
end

#to_sObject



24
25
26
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 24

def to_s
  title_or_label
end

#visibilityObject



166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 166

def visibility
  @visibility ||= if embargo_release_date.present?
                    Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO
                  elsif lease_expiration_date.present?
                    Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE
                  elsif public?
                    Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
                  elsif registered?
                    Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
                  else
                    Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
                  end
end

#workflow_stateObject



180
181
182
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 180

def workflow_state
  first(Solrizer.solr_name('workflow_state_name', :symbol))
end