Class: Parse::AtlasSearch::FacetedResult
- Inherits:
-
Object
- Object
- Parse::AtlasSearch::FacetedResult
- Includes:
- Enumerable
- Defined in:
- lib/parse/atlas_search/result.rb
Overview
Result container for faceted search operations. Provides results, facet counts, and total count.
Instance Attribute Summary collapse
-
#facets ⇒ Hash
readonly
The facet results with counts Format: { facet_name: [{ value: “value”, count: 123 }, …] }.
-
#results ⇒ Array<Parse::Object>
readonly
The search results.
-
#total_count ⇒ Integer
readonly
The total number of matching documents.
Instance Method Summary collapse
-
#count ⇒ Integer
(also: #size)
The number of returned results.
-
#each {|Object| ... } ⇒ Object
Iterate over results.
-
#empty? ⇒ Boolean
True if there are no results.
-
#facet(name) ⇒ Array<Hash>?
Get facet buckets for a specific facet.
-
#facet_names ⇒ Array<Symbol>
The available facet names.
-
#first ⇒ Object?
The first result.
-
#initialize(results:, facets:, total_count:) ⇒ FacetedResult
constructor
A new instance of FacetedResult.
-
#to_a ⇒ Array
The results as an array.
Constructor Details
#initialize(results:, facets:, total_count:) ⇒ FacetedResult
Returns a new instance of FacetedResult.
157 158 159 160 161 |
# File 'lib/parse/atlas_search/result.rb', line 157 def initialize(results:, facets:, total_count:) @results = results @facets = facets @total_count = total_count end |
Instance Attribute Details
#facets ⇒ Hash (readonly)
Returns the facet results with counts Format: { facet_name: [{ value: “value”, count: 123 }, …] }.
149 150 151 |
# File 'lib/parse/atlas_search/result.rb', line 149 def facets @facets end |
#results ⇒ Array<Parse::Object> (readonly)
Returns the search results.
145 146 147 |
# File 'lib/parse/atlas_search/result.rb', line 145 def results @results end |
#total_count ⇒ Integer (readonly)
Returns the total number of matching documents.
152 153 154 |
# File 'lib/parse/atlas_search/result.rb', line 152 def total_count @total_count end |
Instance Method Details
#count ⇒ Integer Also known as: size
Returns the number of returned results.
164 165 166 |
# File 'lib/parse/atlas_search/result.rb', line 164 def count @results.size end |
#each {|Object| ... } ⇒ Object
Iterate over results
177 178 179 |
# File 'lib/parse/atlas_search/result.rb', line 177 def each(&block) @results.each(&block) end |
#empty? ⇒ Boolean
Returns true if there are no results.
171 172 173 |
# File 'lib/parse/atlas_search/result.rb', line 171 def empty? @results.empty? end |
#facet(name) ⇒ Array<Hash>?
Get facet buckets for a specific facet
189 190 191 |
# File 'lib/parse/atlas_search/result.rb', line 189 def facet(name) @facets[name.to_sym] || @facets[name.to_s] end |
#facet_names ⇒ Array<Symbol>
Returns the available facet names.
194 195 196 |
# File 'lib/parse/atlas_search/result.rb', line 194 def facet_names @facets.keys end |
#first ⇒ Object?
Returns the first result.
182 183 184 |
# File 'lib/parse/atlas_search/result.rb', line 182 def first @results.first end |
#to_a ⇒ Array
Returns the results as an array.
199 200 201 |
# File 'lib/parse/atlas_search/result.rb', line 199 def to_a @results.to_a end |