Class: Hyrax::ValkyrieIndexer
- Inherits:
-
Object
- Object
- Hyrax::ValkyrieIndexer
- Defined in:
- app/indexers/hyrax/valkyrie_indexer.rb
Overview
Transforms Valkyrie::Resource
models to solr-ready key-value hashes. Use #to_solr to retrieve the indexable hash.
The default ValkyrieIndexer 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_document| transform(index_document) }; 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, PcdmCollectionIndexer, ValkyrieFileSetIndexer, ValkyrieWorkIndexer
Instance Attribute Summary collapse
- #resource ⇒ Object readonly
Class Method Summary collapse
-
.for(resource:) ⇒ Valkyrie::Indexer
An instance of ValkyrieIndexer or an inherited class based on naming convention.
Instance Method Summary collapse
- #generate_solr_document ⇒ Object private
-
#initialize(resource:) ⇒ ValkyrieIndexer
constructor
private
A new instance of ValkyrieIndexer.
- #to_solr ⇒ Hash<Symbol, Object>
Constructor Details
#initialize(resource:) ⇒ ValkyrieIndexer
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 ValkyrieIndexer.
61 62 63 |
# File 'app/indexers/hyrax/valkyrie_indexer.rb', line 61 def initialize(resource:) @resource = resource end |
Instance Attribute Details
#resource ⇒ Object (readonly)
56 57 58 |
# File 'app/indexers/hyrax/valkyrie_indexer.rb', line 56 def resource @resource end |
Class Method Details
.for(resource:) ⇒ Valkyrie::Indexer
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 return default Hyrax::ValkyrieIndexer if an indexer class following the naming convention is not found.
Returns an instance of ValkyrieIndexer or an inherited class based on naming convention.
98 99 100 101 102 103 104 105 |
# File 'app/indexers/hyrax/valkyrie_indexer.rb', line 98 def for(resource:) case resource when Hyrax::FileSet Hyrax::ValkyrieFileSetIndexer.new(resource: resource) else indexer_class_for(resource).new(resource: resource) end 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.
80 81 82 |
# File 'app/indexers/hyrax/valkyrie_indexer.rb', line 80 def generate_solr_document to_solr.stringify_keys end |
#to_solr ⇒ Hash<Symbol, Object>
68 69 70 71 72 73 74 75 |
# File 'app/indexers/hyrax/valkyrie_indexer.rb', line 68 def to_solr { "id": resource.id.to_s, "date_uploaded_dtsi": resource.created_at, "date_modified_dtsi": resource.updated_at, "has_model_ssim": resource.internal_resource } end |