Class: Valkyrie::Persistence::Solr::Queries::FindMembersQuery
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Solr::Queries::FindMembersQuery
- Defined in:
- lib/valkyrie/persistence/solr/queries/find_members_query.rb
Overview
Responsible for returning all members of a given resource as Resources
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resource_factory ⇒ Object
readonly
Returns the value of attribute resource_factory.
Instance Method Summary collapse
-
#docs ⇒ Array<Hash>
Query Solr for all members of the Valkyrie Resource If a model is specified, this is used to filter the results.
-
#each {|Valkyrie::Resource| ... } ⇒ Object
Queries for all member Documents in the Solr index For each Document, it yields the Valkyrie Resource which was converted from it Results are ordered by the member IDs specified in the Valkyrie Resource attribute.
-
#id ⇒ String
Retrieve the string value for the ID.
-
#initialize(resource:, connection:, resource_factory:, model:) ⇒ FindMembersQuery
constructor
A new instance of FindMembersQuery.
-
#member_ids ⇒ Array<Valkyrie::ID>
Access the IDs of the members for the Valkyrie Resource.
-
#query ⇒ String
Generate the Solr join query using the id_ssi field.
-
#run ⇒ Array<Valkyrie::Resource>
Iterate over each Solr Document and convert each Document into a Valkyrie Resource.
-
#unordered_members ⇒ Array<Valkyrie::Resource>
Retrieving the Solr Documents for the member resources, construct Valkyrie Resources for each.
Constructor Details
#initialize(resource:, connection:, resource_factory:, model:) ⇒ FindMembersQuery
Returns a new instance of FindMembersQuery.
12 13 14 15 16 17 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 12 def initialize(resource:, connection:, resource_factory:, model:) @resource = resource @connection = connection @resource_factory = resource_factory @model = model end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 6 def connection @connection end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 6 def model @model end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 6 def resource @resource end |
#resource_factory ⇒ Object (readonly)
Returns the value of attribute resource_factory.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 6 def resource_factory @resource_factory end |
Instance Method Details
#docs ⇒ Array<Hash>
Query Solr for all members of the Valkyrie Resource If a model is specified, this is used to filter the results
47 48 49 50 51 52 53 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 47 def docs = { q: query, rows: 1_000_000_000 } [:fq] = "{!raw f=internal_resource_ssim}#{model}" if model [:defType] = 'lucene' result = connection.get("select", params: ) result["response"]["docs"] end |
#each {|Valkyrie::Resource| ... } ⇒ Object
Queries for all member Documents in the Solr index For each Document, it yields the Valkyrie Resource which was converted from it Results are ordered by the member IDs specified in the Valkyrie Resource attribute
29 30 31 32 33 34 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 29 def each return [] if resource.id.blank? member_ids.map { |id| unordered_members.find { |member| member.id == id } }.reject(&:nil?).each do |member| yield member end end |
#id ⇒ String
Retrieve the string value for the ID
70 71 72 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 70 def id resource.id.to_s end |
#member_ids ⇒ Array<Valkyrie::ID>
Access the IDs of the members for the Valkyrie Resource
57 58 59 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 57 def member_ids resource.respond_to?(:member_ids) ? Array.wrap(resource.member_ids) : [] end |
#query ⇒ String
Generate the Solr join query using the id_ssi field
64 65 66 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 64 def query "{!join from=#{MEMBER_IDS} to=join_id_ssi}id:#{id}" end |
#run ⇒ Array<Valkyrie::Resource>
Iterate over each Solr Document and convert each Document into a Valkyrie Resource
21 22 23 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 21 def run enum_for(:each) end |
#unordered_members ⇒ Array<Valkyrie::Resource>
Retrieving the Solr Documents for the member resources, construct Valkyrie Resources for each
38 39 40 41 42 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 38 def unordered_members @unordered_members ||= docs.map do |doc| resource_factory.to_resource(object: doc) end end |