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.

Parameters:

  • connection (RSolr::Client)
  • resource_factory (ResourceFactory)
  • model (Class) (defaults to: nil)


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

#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

#countInteger

Queries without making Resrouces and returns the RSolr page_total value

Returns:

  • (Integer)


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

Yields:



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

#queryString

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

Returns:

  • (String)


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

#runArray<Valkyrie::Resource>

Iterate over each Solr Document and convert each Document into a Valkyrie Resource

Returns:



19
20
21
# File 'lib/valkyrie/persistence/solr/queries/find_all_query.rb', line 19

def run
  enum_for(:each)
end