Class: Valkyrie::Persistence::Solr::Queries::FindOrderedReferencesQuery

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

Overview

Responsible for returning all Resources which are referenced in a given Resource‘s property, in the order given in that property.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FindOrderedReferencesQuery.



7
8
9
10
11
12
# File 'lib/valkyrie/persistence/solr/queries/find_ordered_references_query.rb', line 7

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_ordered_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_ordered_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_ordered_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_ordered_references_query.rb', line 6

def resource_factory
  @resource_factory
end

Instance Method Details

#docsObject



31
32
33
34
35
36
# File 'lib/valkyrie/persistence/solr/queries/find_ordered_references_query.rb', line 31

def docs
  options = { q: query, rows: 1_000_000_000 }
  options[:defType] = 'lucene'
  result = connection.get("select", params: options)
  result.fetch('response').fetch('docs')
end

#eachObject



18
19
20
21
22
23
# File 'lib/valkyrie/persistence/solr/queries/find_ordered_references_query.rb', line 18

def each
  # map them off of the property to fix solr's deduplication
  property_values.map { |id| unordered_members.find { |member| member.id == id } } .reject(&:nil?).each do |value|
    yield value
  end
end

#idObject



46
47
48
# File 'lib/valkyrie/persistence/solr/queries/find_ordered_references_query.rb', line 46

def id
  resource.id.to_s
end

#property_valuesObject



38
39
40
# File 'lib/valkyrie/persistence/solr/queries/find_ordered_references_query.rb', line 38

def property_values
  Array.wrap(resource[property])
end

#queryObject



42
43
44
# File 'lib/valkyrie/persistence/solr/queries/find_ordered_references_query.rb', line 42

def query
  "{!join from=#{property}_ssim to=join_id_ssi}id:#{id}"
end

#runObject



14
15
16
# File 'lib/valkyrie/persistence/solr/queries/find_ordered_references_query.rb', line 14

def run
  enum_for(:each)
end

#unordered_membersObject



25
26
27
28
29
# File 'lib/valkyrie/persistence/solr/queries/find_ordered_references_query.rb', line 25

def unordered_members
  @unordered_members ||= docs.map do |doc|
    resource_factory.to_resource(object: doc)
  end
end