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

Returns:

  • (Boolean)


113
114
115
# File 'app/models/concerns/spotlight/solr_document.rb', line 113

def attribute_present?(*_args)
  false
end

#make_private!(exhibit) ⇒ Object



96
97
98
# File 'app/models/concerns/spotlight/solr_document.rb', line 96

def make_private!(exhibit)
  sidecar(exhibit).private!
end

#make_public!(exhibit) ⇒ Object



92
93
94
# File 'app/models/concerns/spotlight/solr_document.rb', line 92

def make_public!(exhibit)
  sidecar(exhibit).public!
end

#private?(exhibit) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'app/models/concerns/spotlight/solr_document.rb', line 100

def private?(exhibit)
  !public?(exhibit)
end

#public?(exhibit) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'app/models/concerns/spotlight/solr_document.rb', line 104

def public?(exhibit)
  sidecar(exhibit).public?
end

#reindexObject



74
75
76
# File 'app/models/concerns/spotlight/solr_document.rb', line 74

def reindex
  # no-op reindex implementation
end

#saveObject



65
66
67
# File 'app/models/concerns/spotlight/solr_document.rb', line 65

def save
  reindex
end

#sidecar(exhibit) ⇒ Object



82
83
84
# File 'app/models/concerns/spotlight/solr_document.rb', line 82

def sidecar(exhibit)
  sidecars.find_or_initialize_by exhibit: exhibit, document_id: id, document_type: self.class.to_s
end

#sidecarsObject



78
79
80
# File 'app/models/concerns/spotlight/solr_document.rb', line 78

def sidecars
  Spotlight::SolrDocumentSidecar.where(document_id: id, document_type: self.class.to_s)
end

#to_solrObject



86
87
88
89
90
# File 'app/models/concerns/spotlight/solr_document.rb', line 86

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/concerns/spotlight/solr_document.rb', line 50

def update(current_exhibit, new_attributes)
  attributes = new_attributes.stringify_keys

  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

  # Note: this causes a save
  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



69
70
71
72
# File 'app/models/concerns/spotlight/solr_document.rb', line 69

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

Returns:

  • (Boolean)


108
109
110
111
# File 'app/models/concerns/spotlight/solr_document.rb', line 108

def uploaded_resource?
  self[self.class.resource_type_field].present? &&
    self[self.class.resource_type_field].include?('spotlight/resources/uploads')
end