Module: Spotlight::SolrDocument

Extended by:
ActiveSupport::Concern
Includes:
GlobalID::Identification, ActiveModelConcern, Finder, SpotlightImages
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/spotlight_images.rb,
app/models/concerns/spotlight/solr_document/uploaded_resource.rb,
app/models/concerns/spotlight/solr_document/active_model_concern.rb

Overview

SolrDocument mixins to add ActiveModel shims and indexing methods

Defined Under Namespace

Modules: ActiveModelConcern, AtomicUpdates, ClassMethods, Finder, SpotlightImages, UploadedResource

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SpotlightImages

#spotlight_image_versions

Methods included from Finder

#blacklight_solr

Methods included from ActiveModelConcern

#destroyed?, #new_record?, #persisted?, #save, #to_key

Class Method Details

.resource_type_fieldObject

rubocop:enable Metrics/LineLength



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

def self.resource_type_field
  :"#{Spotlight::Engine.config.solr_fields.prefix}spotlight_resource_type#{Spotlight::Engine.config.solr_fields.string_suffix}"
end

.solr_field_for_tagger(tagger) ⇒ Object

rubocop:disable Metrics/LineLength



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

def self.solr_field_for_tagger(tagger)
  :"#{Spotlight::Engine.config.solr_fields.prefix}#{tagger.class.model_name.param_key}_#{tagger.id}_tags#{Spotlight::Engine.config.solr_fields.string_suffix}"
end

.visibility_field(exhibit) ⇒ Object



72
73
74
# File 'app/models/concerns/spotlight/solr_document.rb', line 72

def self.visibility_field(exhibit)
  :"#{Spotlight::Engine.config.solr_fields.prefix}#{exhibit.class.model_name.param_key}_#{exhibit.id}_public#{Spotlight::Engine.config.solr_fields.boolean_suffix}"
end

Instance Method Details

#attribute_present?(*_args) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
# File 'app/models/concerns/spotlight/solr_document.rb', line 102

def attribute_present?(*_args)
  false
end

#make_private!(exhibit) ⇒ Object



85
86
87
# File 'app/models/concerns/spotlight/solr_document.rb', line 85

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

#make_public!(exhibit) ⇒ Object



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

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

#private?(exhibit) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'app/models/concerns/spotlight/solr_document.rb', line 89

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

#public?(exhibit) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#reindexObject



55
56
57
# File 'app/models/concerns/spotlight/solr_document.rb', line 55

def reindex
  # no-op reindex implementation
end

#sidecar(exhibit) ⇒ Object



59
60
61
# File 'app/models/concerns/spotlight/solr_document.rb', line 59

def sidecar(exhibit)
  sidecars.find_or_initialize_by exhibit: exhibit
end

#to_solrObject



63
64
65
# File 'app/models/concerns/spotlight/solr_document.rb', line 63

def to_solr
  { self.class.unique_key.to_sym => id }.reverse_merge(sidecars.inject({}) { |a, e| a.merge(e.to_solr) }).merge(tags_to_solr)
end

#update(current_exhibit, new_attributes) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/concerns/spotlight/solr_document.rb', line 35

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(self, with: tags, on: :tags) if tags

  update_exhibit_resource(resource_attributes) if uploaded_resource?
end

#update_exhibit_resource(resource_attributes) ⇒ Object



50
51
52
53
# File 'app/models/concerns/spotlight/solr_document.rb', line 50

def update_exhibit_resource(resource_attributes)
  return unless resource_attributes && resource_attributes['url']
  uploaded_resource.update url: resource_attributes['url']
end

#uploaded_resource?Boolean

Returns:

  • (Boolean)


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

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