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.
-
#standardize_query_result ⇒ Object
readonly
Returns the value of attribute standardize_query_result.
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:, standardize_query_result:) ⇒ 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:, standardize_query_result:) ⇒ FindMembersQuery
Returns a new instance of FindMembersQuery.
12 13 14 15 16 17 18 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 12 def initialize(resource:, connection:, resource_factory:, model:, standardize_query_result:) @resource = resource @connection = connection @resource_factory = resource_factory @model = model @standardize_query_result = standardize_query_result 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 |
#standardize_query_result ⇒ Object (readonly)
Returns the value of attribute standardize_query_result.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 6 def standardize_query_result @standardize_query_result 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
54 55 56 57 58 59 60 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 54 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
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 30 def each return [] unless resource.id.present? if standardize_query_result member_ids.map { |id| unordered_members.find { |member| member.id == id } }.reject(&:nil?).each do |member| yield member end else unordered_members.sort_by { |x| member_ids.index(x.id) }.each do |member| yield member end end end |
#id ⇒ String
Retrieve the string value for the ID
77 78 79 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 77 def id resource.id.to_s end |
#member_ids ⇒ Array<Valkyrie::ID>
Access the IDs of the members for the Valkyrie Resource
64 65 66 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 64 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
71 72 73 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 71 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
22 23 24 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 22 def run enum_for(:each) end |
#unordered_members ⇒ Array<Valkyrie::Resource>
Retrieving the Solr Documents for the member resources, construct Valkyrie Resources for each
45 46 47 48 49 |
# File 'lib/valkyrie/persistence/solr/queries/find_members_query.rb', line 45 def unordered_members @unordered_members ||= docs.map do |doc| resource_factory.to_resource(object: doc) end end |