Class: Hyrax::Listeners::MetadataIndexListener
- Inherits:
-
Object
- Object
- Hyrax::Listeners::MetadataIndexListener
- Defined in:
- app/services/hyrax/listeners/metadata_index_listener.rb
Overview
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
-
#on_collection_deleted(event) ⇒ void
Remove the resource from the index.
-
#on_collection_metadata_updated(event) ⇒ void
Re-index the resource.
-
#on_file_metadata_deleted(event) ⇒ void
Remove the resource from the index.
-
#on_file_metadata_updated(event) ⇒ void
Re-index the resource.
-
#on_object_deleted(event) ⇒ void
Remove the resource from the index.
-
#on_object_membership_updated(event) ⇒ void
Re-index the resource.
-
#on_object_metadata_updated(event) ⇒ void
Re-index the resource.
Instance Method Details
#on_collection_deleted(event) ⇒ void
This method returns an undefined value.
Remove the resource from the index.
Called when ‘collection.deleted’ event is published
81 82 83 84 |
# File 'app/services/hyrax/listeners/metadata_index_listener.rb', line 81 def on_collection_deleted(event) return unless resource?(event.payload[:collection]) Hyrax.index_adapter.delete(resource: event[:collection]) end |
#on_collection_metadata_updated(event) ⇒ void
This method returns an undefined value.
Re-index the resource.
Called when ‘collection.metadata.updated’ event is published
20 21 22 23 |
# File 'app/services/hyrax/listeners/metadata_index_listener.rb', line 20 def (event) return unless resource? event[:collection] Hyrax.index_adapter.save(resource: event[:collection]) end |
#on_file_metadata_deleted(event) ⇒ void
This method returns an undefined value.
Remove the resource from the index.
Called when ‘file.metadata.deleted’ event is published
92 93 94 95 |
# File 'app/services/hyrax/listeners/metadata_index_listener.rb', line 92 def (event) return unless resource? event.payload[:metadata] Hyrax.index_adapter.delete(resource: event[:metadata]) end |
#on_file_metadata_updated(event) ⇒ void
This method returns an undefined value.
Re-index the resource.
Called when ‘file.metadata.updated’ event is published
31 32 33 34 |
# File 'app/services/hyrax/listeners/metadata_index_listener.rb', line 31 def (event) return unless resource? event[:metadata] Hyrax.index_adapter.save(resource: event[:metadata]) end |
#on_object_deleted(event) ⇒ void
This method returns an undefined value.
Remove the resource from the index.
Called when ‘object.deleted’ event is published
70 71 72 73 |
# File 'app/services/hyrax/listeners/metadata_index_listener.rb', line 70 def on_object_deleted(event) return unless resource?(event.payload[:object]) Hyrax.index_adapter.delete(resource: event[:object]) end |
#on_object_membership_updated(event) ⇒ void
This method returns an undefined value.
Re-index the resource.
Called when ‘object.membership.updated’ event is published
42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/hyrax/listeners/metadata_index_listener.rb', line 42 def on_object_membership_updated(event) resource = event.to_h.fetch(:object) { Hyrax.query_service.find_by(id: event[:object_id]) } return unless resource?(resource) Hyrax.index_adapter.save(resource: resource) rescue Valkyrie::Persistence::ObjectNotFoundError => err Hyrax.logger.error("Tried to index for an #{event.id} event with " \ "payload #{event.payload}, but failed due to error:\n"\ "\t#{err.}") end |
#on_object_metadata_updated(event) ⇒ void
This method returns an undefined value.
Re-index the resource.
Called when ‘object.metadata.updated’ event is published
59 60 61 62 |
# File 'app/services/hyrax/listeners/metadata_index_listener.rb', line 59 def (event) return unless resource? event[:object] Hyrax.index_adapter.save(resource: event[:object]) end |