Class: Valkyrie::Persistence::Solr::ModelConverter
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Solr::ModelConverter
- Defined in:
- lib/valkyrie/persistence/solr/model_converter.rb
Overview
Responsible for converting a Resource into hashes for indexing into Solr.
Defined Under Namespace
Classes: BooleanPropertyValue, CompositeSolrRow, DateTimePropertyValue, EnumerableValue, FloatPropertyValue, IDPropertyValue, IntegerPropertyValue, LiteralPropertyValue, NestedObjectValue, Property, SharedStringPropertyValue, SolrMapperValue, SolrRow, StringPropertyValue, URIPropertyValue
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resource_factory ⇒ Object
readonly
Returns the value of attribute resource_factory.
Instance Method Summary collapse
-
#convert! ⇒ Hash
Converts the Valkyrie Resource to the Solr Document.
-
#created_at ⇒ String
ISO-8601 timestamp in UTC of the created_at for this solr document.
-
#id ⇒ String
Access the ID for the Valkyrie Resource being converted to a Solr Document.
-
#indexer_solr(resource) ⇒ Hash
Generate the Solr Document for a Valkyrie Resource using the indexer.
-
#initialize(resource, resource_factory:) ⇒ ModelConverter
constructor
A new instance of ModelConverter.
-
#to_h ⇒ Hash
Solr document to index.
-
#updated_at ⇒ String
reasons we’re generating our own.
Constructor Details
#initialize(resource, resource_factory:) ⇒ ModelConverter
Returns a new instance of ModelConverter.
11 12 13 14 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 11 def initialize(resource, resource_factory:) @resource = resource @resource_factory = resource_factory end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 6 def resource @resource end |
#resource_factory ⇒ Object (readonly)
Returns the value of attribute resource_factory.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 6 def resource_factory @resource_factory end |
Instance Method Details
#convert! ⇒ Hash
this modifies the Solr Document for the conversion
Converts the Valkyrie Resource to the Solr Document
19 20 21 22 23 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 19 def convert! # Appends the resource type to the Solr Document to_h.merge(Valkyrie::Persistence::Solr::Queries::MODEL.to_sym => [resource.internal_resource]) .merge(indexer_solr(resource)) end |
#created_at ⇒ String
Returns ISO-8601 timestamp in UTC of the created_at for this solr document.
40 41 42 43 44 45 46 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 40 def created_at if resource_attributes[:created_at] DateTime.parse(resource_attributes[:created_at].to_s).utc.iso8601 else Time.current.utc.iso8601(6) end end |
#id ⇒ String
Access the ID for the Valkyrie Resource being converted to a Solr Document
34 35 36 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 34 def id resource.id.to_s end |
#indexer_solr(resource) ⇒ Hash
Generate the Solr Document for a Valkyrie Resource using the indexer
28 29 30 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 28 def indexer_solr(resource) resource_indexer.new(resource: resource).to_solr end |
#to_h ⇒ Hash
Returns Solr document to index.
57 58 59 60 61 62 63 64 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 57 def to_h { "id": id, "join_id_ssi": "id-#{id}", "created_at_dtsi": created_at, "updated_at_dtsi": updated_at }.merge(add_single_values(attribute_hash)).merge(lock_hash) end |
#updated_at ⇒ String
Solr stores its own updated_at timestamp, but for performance
reasons we’re generating our own. Without doing so, every time we add a new document we’d have to do a GET to find out the timestamp.
52 53 54 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 52 def updated_at Time.current.utc.iso8601(6) end |