Class: Valkyrie::Indexing::Solr::IndexingAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/indexing/solr/indexing_adapter.rb

Constant Summary collapse

COMMIT_PARAMS =
{ softCommit: true }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection: default_connection) ⇒ IndexingAdapter

Returns a new instance of IndexingAdapter.

Parameters:

  • connection (RSolr::Client) (defaults to: default_connection)

    The RSolr connection to index to.



16
17
18
# File 'lib/valkyrie/indexing/solr/indexing_adapter.rb', line 16

def initialize(connection: default_connection)
  @connection = connection
end

Instance Attribute Details

#connectionRSolr::Client

Returns:

  • (RSolr::Client)


12
13
14
# File 'lib/valkyrie/indexing/solr/indexing_adapter.rb', line 12

def connection
  @connection
end

Instance Method Details

#delete(resource:) ⇒ Array<Valkyrie::Resource>

Deletes a Solr Document using the ID

Returns:

  • (Array<Valkyrie::Resource>)

    resources which have been deleted from Solr



30
31
32
# File 'lib/valkyrie/indexing/solr/indexing_adapter.rb', line 30

def delete(resource:)
  connection.delete_by_id resource.id.to_s, params: COMMIT_PARAMS
end

#reset!Object



40
41
42
# File 'lib/valkyrie/indexing/solr/indexing_adapter.rb', line 40

def reset!
  self.connection = default_connection
end

#save(resource:) ⇒ Object



20
21
22
# File 'lib/valkyrie/indexing/solr/indexing_adapter.rb', line 20

def save(resource:)
  persist([resource])
end

#save_all(resources:) ⇒ Object



24
25
26
# File 'lib/valkyrie/indexing/solr/indexing_adapter.rb', line 24

def save_all(resources:)
  persist(resources)
end

#wipe!Object

Delete the Solr index of all Documents



35
36
37
38
# File 'lib/valkyrie/indexing/solr/indexing_adapter.rb', line 35

def wipe!
  connection.delete_by_query("*:*")
  connection.commit
end