Class: Hyrax::Indexers::ResourceIndexer
- Inherits:
-
Object
- Object
- Hyrax::Indexers::ResourceIndexer
- Defined in:
- app/indexers/hyrax/indexers/resource_indexer.rb
Overview
Transforms Valkyrie::Resource
models to solr-ready key-value hashes. Use #to_solr to retrieve the indexable hash.
The default ResourceIndexer implementation provides minimal indexing for the Valkyrie id and the reserved #created_at
and #updated_at
attributes.
Custom indexers inheriting from others are responsible for providing a full index hash. A common pattern for doing this is to employ method composition to retrieve the parent’s data, then modify it: def to_solr; super.tap { |index_doc| transform(index_doc) }; end. This technique creates infinitely composible index building behavior, with indexers that can always see the state of the resource and the full current index document.
It’s recommended to never modify the state of resource
in an indexer.
Direct Known Subclasses
AdministrativeSetIndexer, FileSetIndexer, PcdmCollectionIndexer, PcdmObjectIndexer, ValkyrieIndexer
Instance Attribute Summary collapse
- #resource ⇒ Object readonly
Class Method Summary collapse
-
.for(resource:) ⇒ Hyrax::Indexers::ResourceIndexer
An instance of
Hyrax::Indexers::ResourceIndexer
or an inherited class.
Instance Method Summary collapse
- #generate_solr_document ⇒ Object private
-
#initialize(resource:) ⇒ ResourceIndexer
constructor
private
A new instance of ResourceIndexer.
- #to_solr ⇒ HashWithIndifferentAccess<Symbol, Object>
Constructor Details
#initialize(resource:) ⇒ ResourceIndexer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ResourceIndexer.
34 35 36 |
# File 'app/indexers/hyrax/indexers/resource_indexer.rb', line 34 def initialize(resource:) @resource = resource end |
Instance Attribute Details
#resource ⇒ Object (readonly)
29 30 31 |
# File 'app/indexers/hyrax/indexers/resource_indexer.rb', line 29 def resource @resource end |
Class Method Details
.for(resource:) ⇒ Hyrax::Indexers::ResourceIndexer
This factory will attempt to return an indexer following a naming convention where the indexer for a resource class is expected to be the class name appended with ‘Indexer’. It will then attempt to select an indexer based on the class of the resource, and will return a default Hyrax::Indexers::ResourceIndexer if an indexer class is otherwise not found.
Returns an instance of Hyrax::Indexers::ResourceIndexer
or an inherited class.
77 78 79 80 81 82 |
# File 'app/indexers/hyrax/indexers/resource_indexer.rb', line 77 def for(resource:) klass = "#{resource.class.name}Indexer".safe_constantize klass = nil unless klass.is_a?(Class) && klass.instance_methods.include?(:to_solr) klass ||= Hyrax::Indexers::ResourceIndexer(resource.class) klass.new(resource: resource) end |
Instance Method Details
#generate_solr_document ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
provided for ActiveFedora compatibility.
57 58 59 |
# File 'app/indexers/hyrax/indexers/resource_indexer.rb', line 57 def generate_solr_document to_solr.stringify_keys end |
#to_solr ⇒ HashWithIndifferentAccess<Symbol, Object>
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/indexers/hyrax/indexers/resource_indexer.rb', line 41 def to_solr { "id": resource.id.to_s, "date_uploaded_dtsi": resource.created_at, "date_modified_dtsi": resource.updated_at, "system_create_dtsi": resource.created_at, "system_modified_dtsi": resource.updated_at, "has_model_ssim": resource.to_rdf_representation, "human_readable_type_tesim": resource.human_readable_type, "alternate_ids_sim": resource.alternate_ids.map(&:to_s) }.with_indifferent_access end |