Class: Valkyrie::Persistence::Solr::ModelConverter

Inherits:
Object
  • Object
show all
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, IDPropertyValue, IntegerPropertyValue, LiteralPropertyValue, NestedObjectValue, NilPropertyValue, Property, SharedStringPropertyValue, SolrMapperValue, SolrRow, StringPropertyValue, URIPropertyValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, resource_factory:) ⇒ ModelConverter

Returns a new instance of ModelConverter.



8
9
10
11
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 8

def initialize(resource, resource_factory:)
  @resource = resource
  @resource_factory = resource_factory
end

Instance Attribute Details

#resourceObject (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_factoryObject (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!Object



13
14
15
16
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 13

def convert!
  to_h.merge(Valkyrie::Persistence::Solr::Queries::MODEL.to_sym => [resource.internal_resource])
      .merge(indexer_solr(resource))
end

#created_atString

Returns ISO-8601 timestamp in UTC of the created_at for this solr document.

Returns:

  • (String)

    ISO-8601 timestamp in UTC of the created_at for this solr document.



29
30
31
32
33
34
35
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 29

def created_at
  if resource_attributes[:created_at]
    DateTime.parse(resource_attributes[:created_at].to_s).utc.iso8601
  else
    Time.current.utc.iso8601
  end
end

#idString

Returns The solr document ID.

Returns:

  • (String)

    The solr document ID



23
24
25
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 23

def id
  resource.id.to_s
end

#indexer_solr(resource) ⇒ Object



18
19
20
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 18

def indexer_solr(resource)
  resource_indexer.new(resource: resource).to_solr
end

#to_hHash

Returns Solr document to index.

Returns:

  • (Hash)

    Solr document to index.



38
39
40
41
42
43
44
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 38

def to_h
  {
    "id": id,
    "join_id_ssi": "id-#{id}",
    "created_at_dtsi": created_at
  }.merge(attribute_hash)
end