Class: Hyrax::Listeners::MetadataIndexListener

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/listeners/metadata_index_listener.rb

Overview

Note:

This listener makes no attempt to avoid reindexing when no metadata has actually changed, or when real metadata changes won't impact the indexed data. We trust that published metadata update events represent actual changes to object metadata, and that the indexing adapter optimizes reasonably for actual index document contents.

Reindexes resources when their metadata is updated.

Instance Method Summary collapse

Instance Method Details

#on_object_deleted(event) ⇒ Object

Remove the resource from the index.

Parameters:

  • event (Dry::Event)

29
30
31
32
33
34
# File 'app/services/hyrax/listeners/metadata_index_listener.rb', line 29

def on_object_deleted(event)
  log_non_resource(event.payload) && return unless
    event.payload[:object].is_a?(Valkyrie::Resource)

  Hyrax.index_adapter.delete(resource: event[:object])
end

#on_object_metadata_updated(event) ⇒ Object

Re-index the resource.

Parameters:

  • event (Dry::Event)

18
19
20
21
22
23
# File 'app/services/hyrax/listeners/metadata_index_listener.rb', line 18

def (event)
  log_non_resource(event) && return unless
    event[:object].is_a?(Valkyrie::Resource)

  Hyrax.index_adapter.save(resource: event[:object])
end