Class: Valkyrie::Persistence::Solr::Queries::FindInverseReferencesQuery

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

Overview

Responsible for efficiently returning all Resources which reference a Resource in a given property.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource: nil, id: nil, property:, connection:, resource_factory:) ⇒ FindInverseReferencesQuery

Returns a new instance of FindInverseReferencesQuery.

Parameters:



12
13
14
15
16
17
# File 'lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb', line 12

def initialize(resource: nil, id: nil, property:, connection:, resource_factory:)
  @id = id ? id : resource.id
  @property = property
  @connection = connection
  @resource_factory = resource_factory
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb', line 6

def connection
  @connection
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb', line 6

def id
  @id
end

#propertyObject (readonly)

Returns the value of attribute property.



6
7
8
# File 'lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb', line 6

def property
  @property
end

#resource_factoryObject (readonly)

Returns the value of attribute resource_factory.



6
7
8
# File 'lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb', line 6

def resource_factory
  @resource_factory
end

Instance Method Details

#each {|Valkyrie::Resource| ... } ⇒ Object

Queries for all Documents in the Solr index For each Document, it yields the Valkyrie Resource which was converted from it

Yields:



28
29
30
31
32
33
34
35
36
# File 'lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb', line 28

def each
  docs = DefaultPaginator.new
  while docs.has_next?
    docs = connection.paginate(docs.next_page, docs.per_page, "select", params: { q: query })["response"]["docs"]
    docs.each do |doc|
      yield resource_factory.to_resource(object: doc)
    end
  end
end

#queryHash

Note:

the field used here is a _ssim dynamic field and the value is prefixed by “id-”

Query Solr for for all documents with the ID in the requested field

Returns:

  • (Hash)


41
42
43
# File 'lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb', line 41

def query
  "#{property}_ssim:id-#{id}"
end

#runArray<Valkyrie::Resource>

Iterate over each Solr Document and convert each Document into a Valkyrie Resource

Returns:



21
22
23
# File 'lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb', line 21

def run
  enum_for(:each)
end