Class: Solr::Query::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/solr/query/response.rb,
lib/solr/query/response/parser.rb,
lib/solr/query/response/spellcheck.rb,
lib/solr/query/response/facet_value.rb,
lib/solr/query/response/field_facets.rb

Defined Under Namespace

Classes: FacetValue, FieldFacets, Parser, Spellcheck

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(documents:, available_facets: [], spellcheck: Solr::Query::Response::Spellcheck.empty) ⇒ Response

Returns a new instance of Response.



33
34
35
36
37
# File 'lib/solr/query/response.rb', line 33

def initialize(documents:, available_facets: [], spellcheck: Solr::Query::Response::Spellcheck.empty)
  @documents = documents
  @available_facets = available_facets
  @spellcheck = spellcheck
end

Instance Attribute Details

#available_facetsObject (readonly)

Returns the value of attribute available_facets.



9
10
11
# File 'lib/solr/query/response.rb', line 9

def available_facets
  @available_facets
end

#documentsObject (readonly)

Returns the value of attribute documents.



9
10
11
# File 'lib/solr/query/response.rb', line 9

def documents
  @documents
end

#spellcheckObject (readonly)

Returns the value of attribute spellcheck.



9
10
11
# File 'lib/solr/query/response.rb', line 9

def spellcheck
  @spellcheck
end

Class Method Details

.emptyObject



12
13
14
# File 'lib/solr/query/response.rb', line 12

def empty
  new(documents: Solr::DocumentCollection.empty)
end

.empty_groupedObject



16
17
18
# File 'lib/solr/query/response.rb', line 16

def empty_grouped
  new(documents: Solr::GroupedDocumentCollection.empty)
end

.manual_grouped_documents(ids) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/solr/query/response.rb', line 20

def manual_grouped_documents(ids)
  documents = ids.map { |id| Solr::Document.new(id: id) }
  group_counts = ids.each_with_object({}) do |id, acc|
    acc[id] = 1
  end
  new(documents: Solr::GroupedDocumentCollection.new(
    documents: documents,
    total_count: ids.count,
    group_counts: group_counts
  ))
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/solr/query/response.rb', line 43

def empty?
  total_count.zero?
end

#total_countObject



39
40
41
# File 'lib/solr/query/response.rb', line 39

def total_count
  @documents.total_count
end