module ActiveFedora::Indexing

Mix in this module to update Solr on save. Assign a new indexer at the class level where this is mixed in

(or define an #indexing_service method)
to change the document contents sent to solr

Example indexing services are: @see ActiveFedora::IndexingService @see ActiveFedora::RDF::IndexingService

Public Instance Methods

indexing_service() click to toggle source
# File lib/active_fedora/indexing.rb, line 45
def indexing_service
  @indexing_service ||= self.class.indexer.new(self)
end
to_solr(_solr_doc = {}, _opts = {}) click to toggle source

Return a Hash representation of this object where keys in the hash are appropriate Solr field names. @param [Hash] _solr_doc (optional) Hash to insert the fields into @param [Hash] _opts (optional) If opts == true, the base object metadata and the RELS-EXT datastream will be omitted. This is mainly to support shelver, which calls to_solr for each model an object subscribes to.

# File lib/active_fedora/indexing.rb, line 41
def to_solr(_solr_doc = {}, _opts = {})
  indexing_service.generate_solr_document
end
update_index() click to toggle source

Updates Solr index with self. rubocop:disable Naming/VariableName

# File lib/active_fedora/indexing.rb, line 51
def update_index
  SolrService.add(to_solr, softCommit: true)
end

Protected Instance Methods

create_needs_index?() click to toggle source

Determines whether a create operation causes a solr index of this object by default. Override this if you need different behavior.

# File lib/active_fedora/indexing.rb, line 60
def create_needs_index?
  ActiveFedora.enable_solr_updates?
end
update_needs_index?() click to toggle source

Determines whether an update operation causes a solr index of this object by default. Override this if you need different behavior

# File lib/active_fedora/indexing.rb, line 66
def update_needs_index?
  ActiveFedora.enable_solr_updates?
end

Private Instance Methods

_create_record(options = {}) click to toggle source

index the record after it has been persisted to Fedora

Calls superclass method
# File lib/active_fedora/indexing.rb, line 73
def _create_record(options = {})
  super
  update_index if create_needs_index? && options.fetch(:update_index, true)
  true
end
_update_record(options = {}) click to toggle source

index the record after it has been updated in Fedora

Calls superclass method
# File lib/active_fedora/indexing.rb, line 80
def _update_record(options = {})
  super
  update_index if update_needs_index? && options.fetch(:update_index, true)
  true
end