Class: Valkyrie::Persistence::Solr::Queries::FindReferencesQuery

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

Overview

Responsible for efficently returning all Resources which are referenced in a given Resource‘s property.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:, property:, connection:, resource_factory:) ⇒ FindReferencesQuery

Returns a new instance of FindReferencesQuery.

Parameters:



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

def initialize(resource:, property:, connection:, resource_factory:)
  @resource = resource
  @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_references_query.rb', line 6

def connection
  @connection
end

#propertyObject (readonly)

Returns the value of attribute property.



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

def property
  @property
end

#resourceObject (readonly)

Returns the value of attribute resource.



6
7
8
# File 'lib/valkyrie/persistence/solr/queries/find_references_query.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/queries/find_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
37
38
# File 'lib/valkyrie/persistence/solr/queries/find_references_query.rb', line 28

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

#idString

Retrieve the string value for the ID

Returns:

  • (String)


49
50
51
# File 'lib/valkyrie/persistence/solr/queries/find_references_query.rb', line 49

def id
  resource.id.to_s
end

#queryString

Generate the Solr join query using the id_ssi field



43
44
45
# File 'lib/valkyrie/persistence/solr/queries/find_references_query.rb', line 43

def query
  "{!join from=#{property}_ssim to=join_id_ssi}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_references_query.rb', line 21

def run
  enum_for(:each)
end