Module: Spotlight::SolrDocument
- Extended by:
- ActiveSupport::Concern
- Includes:
- GlobalID::Identification, Finder
- Defined in:
- app/models/concerns/spotlight/solr_document.rb,
app/models/concerns/spotlight/solr_document/finder.rb,
app/models/concerns/spotlight/solr_document/atomic_updates.rb,
app/models/concerns/spotlight/solr_document/uploaded_resource.rb
Overview
SolrDocument mixins to add ActiveModel shims and indexing methods
Defined Under Namespace
Modules: AtomicUpdates, ClassMethods, Finder, UploadedResource
Instance Method Summary
collapse
Methods included from Finder
#==, #blacklight_solr
Instance Method Details
#attribute_present?(*_args) ⇒ Boolean
120
121
122
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 120
def attribute_present?(*_args)
false
end
|
#make_private!(exhibit) ⇒ Object
103
104
105
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 103
def make_private!(exhibit)
sidecar(exhibit).private!
end
|
#make_public!(exhibit) ⇒ Object
99
100
101
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 99
def make_public!(exhibit)
sidecar(exhibit).public!
end
|
#private?(exhibit) ⇒ Boolean
107
108
109
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 107
def private?(exhibit)
!public?(exhibit)
end
|
#public?(exhibit) ⇒ Boolean
111
112
113
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 111
def public?(exhibit)
sidecar(exhibit).public?
end
|
#reindex ⇒ Object
81
82
83
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 81
def reindex
end
|
#save ⇒ Object
71
72
73
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 71
def save
reindex
end
|
#sidecar(exhibit) ⇒ Object
89
90
91
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 89
def sidecar(exhibit)
sidecars.find_or_initialize_by exhibit: exhibit, document_id: id, document_type: self.class.to_s
end
|
#sidecars ⇒ Object
85
86
87
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 85
def sidecars
Spotlight::SolrDocumentSidecar.where(document_id: id, document_type: self.class.to_s)
end
|
#to_solr ⇒ Object
93
94
95
96
97
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 93
def to_solr
{ self.class.unique_key.to_sym => id }.reverse_merge(sidecars.inject({}) { |acc, elem| acc.merge(elem.to_solr) })
.merge(tags_to_solr)
.merge(exhibits_to_solr)
end
|
#update(current_exhibit, new_attributes) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 56
def update(current_exhibit, new_attributes)
attributes = convert_incoming_attributes(new_attributes)
custom_data = attributes.delete('sidecar')
tags = attributes.delete('exhibit_tag_list')
resource_attributes = attributes.delete('uploaded_resource')
sidecar(current_exhibit).update(custom_data) if custom_data
current_exhibit.tag(sidecar(current_exhibit), with: tags, on: :tags) if tags
update_exhibit_resource(resource_attributes) if uploaded_resource?
end
|
#update_exhibit_resource(resource_attributes) ⇒ Object
75
76
77
78
79
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 75
def update_exhibit_resource(resource_attributes)
return unless resource_attributes && resource_attributes['url']
uploaded_resource.upload.update image: resource_attributes['url']
end
|
#uploaded_resource? ⇒ Boolean
115
116
117
118
|
# File 'app/models/concerns/spotlight/solr_document.rb', line 115
def uploaded_resource?
self[self.class.resource_type_field].present? &&
self[self.class.resource_type_field].include?('spotlight/resources/uploads')
end
|