class Solr::GroupedDocumentCollection

Attributes

group_counts[R]

Public Class Methods

empty() click to toggle source
# File lib/solr/grouped_document_collection.rb, line 5
def self.empty
  new(documents: [], total_count: 0, group_counts: {})
end
new(documents:, total_count:, group_counts:) click to toggle source
Calls superclass method Solr::DocumentCollection::new
# File lib/solr/grouped_document_collection.rb, line 9
def initialize(documents:, total_count:, group_counts:)
  super(documents: documents, total_count: total_count)
  @group_counts = group_counts
end

Public Instance Methods

+(other) click to toggle source
# File lib/solr/grouped_document_collection.rb, line 29
def +(other)
  other_group_counts = other.is_a?(Solr::GroupedDocumentCollection) ? other.group_counts : {}
  self.class.new(
    documents: documents + other.documents,
    total_count: total_count + other.total_count,
    group_counts: group_counts.merge(other_group_counts)
  )
end
first(n) click to toggle source
# File lib/solr/grouped_document_collection.rb, line 14
def first(n)
  new_documents = documents.first(n)
  self.class.new(documents: new_documents,
                 total_count: new_documents.count, group_counts: group_counts)
end
slice(range) click to toggle source
# File lib/solr/grouped_document_collection.rb, line 20
def slice(range)
  new_documents = documents[range]
  if new_documents
    self.class.new(documents: new_documents, total_count: new_documents.count, group_counts: group_counts)
  else
    self.class.empty
  end
end