Class: Valkyrie::Persistence::Solr::Queries::FindAllQuery
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Solr::Queries::FindAllQuery
- Defined in:
- lib/valkyrie/persistence/solr/queries/find_all_query.rb
Overview
Responsible for efficiently returning all objects in the solr repository 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_factory ⇒ Object
readonly
Returns the value of attribute resource_factory.
Instance Method Summary collapse
-
#count ⇒ Integer
Queries without making Resrouces and returns the RSolr page_total value.
-
#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.
-
#initialize(connection:, resource_factory:, model: nil) ⇒ FindAllQuery
constructor
A new instance of FindAllQuery.
-
#query ⇒ String
Generates the Solr query for retrieving all Documents in the index If a model is specified for the query, it is scoped to that Valkyrie resource type.
-
#run ⇒ Array<Valkyrie::Resource>
Iterate over each Solr Document and convert each Document into a Valkyrie Resource.
Constructor Details
#initialize(connection:, resource_factory:, model: nil) ⇒ FindAllQuery
Returns a new instance of FindAllQuery.
11 12 13 14 15 |
# File 'lib/valkyrie/persistence/solr/queries/find_all_query.rb', line 11 def initialize(connection:, resource_factory:, model: nil) @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_all_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_all_query.rb', line 6 def model @model end |
#resource_factory ⇒ Object (readonly)
Returns the value of attribute resource_factory.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/queries/find_all_query.rb', line 6 def resource_factory @resource_factory end |
Instance Method Details
#count ⇒ Integer
Queries without making Resrouces and returns the RSolr page_total value
38 39 40 |
# File 'lib/valkyrie/persistence/solr/queries/find_all_query.rb', line 38 def count connection.get("select", params: { q: query })["response"]["numFound"].to_s.to_i end |
#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
26 27 28 29 30 31 32 33 34 |
# File 'lib/valkyrie/persistence/solr/queries/find_all_query.rb', line 26 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 |
#query ⇒ String
Generates the Solr query for retrieving all Documents in the index If a model is specified for the query, it is scoped to that Valkyrie resource type
45 46 47 48 49 50 51 |
# File 'lib/valkyrie/persistence/solr/queries/find_all_query.rb', line 45 def query if !model "*:*" else "#{Valkyrie::Persistence::Solr::Queries::MODEL}:#{model}" end end |
#run ⇒ Array<Valkyrie::Resource>
Iterate over each Solr Document and convert each Document into a Valkyrie Resource
19 20 21 |
# File 'lib/valkyrie/persistence/solr/queries/find_all_query.rb', line 19 def run enum_for(:each) end |