Class: Valkyrie::Persistence::Solr::MetadataAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/persistence/solr/metadata_adapter.rb

Overview

MetadataAdapter for Solr Adapter.

This adapter persists resources as hashes to an RSolr connection.

Examples:

Instantiate a Solr MetadataAdapter for Blacklight

Valkyrie::Persistence::Solr::MetadataAdapter.new(
  connection: Blacklight.default_index.connection
)

Instantiate a Solr MetadataAdapter with just RSolr

Valkyrie::Persistence::Solr::MetadataAdapter.new(
  connection: RSolr.connect(url: "http://127.0.0.1:8983/solr/core")
)

Instantiate a Solr MetadataAdapter with custom indexers

Valkyrie::Persistence::Solr::MetadataAdapter.new(
  connection: Blacklight.default_index.connection,
  resource_indexer: CompositeIndexer.new(
    Valkyrie::Indexers::AccessControlsIndexer,
    MyIndexer
  )
)

Defined Under Namespace

Classes: NullIndexer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:, resource_indexer: NullIndexer, write_only: false, soft_commit: true) ⇒ MetadataAdapter

Returns a new instance of MetadataAdapter.

Parameters:

  • connection (RSolr::Client)

    The RSolr connection to index to.

  • resource_indexer (Class, #to_solr) (defaults to: NullIndexer)

    An indexer which is able to receive a ‘resource` argument and then has an instance method `#to_solr`

  • write_only (Boolean) (defaults to: false)

    If true act as a write only adapter.

  • soft_commit (Boolean) (defaults to: true)

    If false, don’t soft commit.



36
37
38
39
40
41
# File 'lib/valkyrie/persistence/solr/metadata_adapter.rb', line 36

def initialize(connection:, resource_indexer: NullIndexer, write_only: false, soft_commit: true)
  @connection = connection
  @resource_indexer = resource_indexer
  @write_only = write_only
  @soft_commit = soft_commit
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



30
31
32
# File 'lib/valkyrie/persistence/solr/metadata_adapter.rb', line 30

def connection
  @connection
end

#resource_indexerObject (readonly)

Returns the value of attribute resource_indexer.



30
31
32
# File 'lib/valkyrie/persistence/solr/metadata_adapter.rb', line 30

def resource_indexer
  @resource_indexer
end

#write_onlyObject (readonly)

Returns the value of attribute write_only.



30
31
32
# File 'lib/valkyrie/persistence/solr/metadata_adapter.rb', line 30

def write_only
  @write_only
end

Instance Method Details

#idValkyrie::ID

Generate the Valkyrie ID for this unique metadata adapter This uses the URL of the Solr endpoint to ensure that this is unique

Returns:



69
70
71
# File 'lib/valkyrie/persistence/solr/metadata_adapter.rb', line 69

def id
  @id ||= Valkyrie::ID.new(Digest::MD5.hexdigest(connection.base_uri.to_s))
end

#persisterValkyrie::Persistence::Solr::Persister

Returns The solr persister.

Returns:



44
45
46
# File 'lib/valkyrie/persistence/solr/metadata_adapter.rb', line 44

def persister
  @persister ||= Valkyrie::Persistence::Solr::Persister.new(adapter: self)
end

#query_serviceValkyrie::Persistence::Solr::QueryService

Returns The solr query service.

Returns:



58
59
60
61
62
63
64
# File 'lib/valkyrie/persistence/solr/metadata_adapter.rb', line 58

def query_service
  @query_service ||= Valkyrie::Persistence::Solr::QueryService.new(
    connection: connection,
    resource_factory: resource_factory,
    adapter: self
  )
end

#resource_factoryValkyrie::Persistence::Solr::ResourceFactory

Returns A resource factory to convert a resource to a solr document and back.

Returns:



75
76
77
# File 'lib/valkyrie/persistence/solr/metadata_adapter.rb', line 75

def resource_factory
  Valkyrie::Persistence::Solr::ResourceFactory.new(resource_indexer: resource_indexer, adapter: self)
end

#soft_commit?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/valkyrie/persistence/solr/metadata_adapter.rb', line 52

def soft_commit?
  @soft_commit
end

#write_only?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/valkyrie/persistence/solr/metadata_adapter.rb', line 48

def write_only?
  write_only
end