Class: Valkyrie::Persistence::Solr::Queries::FindAllQuery

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(connection:, resource_factory:, model: nil) ⇒ FindAllQuery

Returns a new instance of FindAllQuery.



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

def initialize(connection:, resource_factory:, model: nil)
  @connection = connection
  @resource_factory = resource_factory
  @model = model
end

Instance Attribute Details

#connectionObject (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

#modelObject (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_factoryObject (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

#eachObject



17
18
19
20
21
22
23
24
25
# File 'lib/valkyrie/persistence/solr/queries/find_all_query.rb', line 17

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

#queryObject



27
28
29
30
31
32
33
# File 'lib/valkyrie/persistence/solr/queries/find_all_query.rb', line 27

def query
  if !model
    "*:*"
  else
    "#{Valkyrie::Persistence::Solr::Queries::MODEL}:#{model}"
  end
end

#runObject



13
14
15
# File 'lib/valkyrie/persistence/solr/queries/find_all_query.rb', line 13

def run
  enum_for(:each)
end