Class: Typesensual::Search::Results
- Inherits:
-
Object
- Object
- Typesensual::Search::Results
- Defined in:
- lib/typesensual/search/results.rb
Instance Method Summary collapse
- #count ⇒ Object
- #current_page ⇒ Object
- #facets ⇒ Object
- #first_page? ⇒ Boolean
- #grouped_hits ⇒ Object
- #hits ⇒ Object
-
#initialize(results, search:) ⇒ Results
constructor
A new instance of Results.
- #last_page? ⇒ Boolean
- #next_page ⇒ Object
- #out_of ⇒ Object
- #per_page ⇒ Object
- #prev_page ⇒ Object
- #search_time_ms ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(results, search:) ⇒ Results
Returns a new instance of Results.
6 7 8 9 |
# File 'lib/typesensual/search/results.rb', line 6 def initialize(results, search:) @results = results @search = search end |
Instance Method Details
#count ⇒ Object
19 20 21 |
# File 'lib/typesensual/search/results.rb', line 19 def count @results['found'] end |
#current_page ⇒ Object
27 28 29 |
# File 'lib/typesensual/search/results.rb', line 27 def current_page @results['page'] end |
#facets ⇒ Object
59 60 61 62 63 |
# File 'lib/typesensual/search/results.rb', line 59 def facets @search.facet_keys.zip(@results['facet_counts']).to_h do |(key, facet)| [key, Facet.new(key, facet)] end end |
#first_page? ⇒ Boolean
31 32 33 |
# File 'lib/typesensual/search/results.rb', line 31 def first_page? current_page == 1 end |
#grouped_hits ⇒ Object
15 16 17 |
# File 'lib/typesensual/search/results.rb', line 15 def grouped_hits @results['grouped_hits'].map { |hit| GroupedHit.new(hit) } end |
#hits ⇒ Object
11 12 13 |
# File 'lib/typesensual/search/results.rb', line 11 def hits @results['hits'].map { |hit| Hit.new(hit) } end |
#last_page? ⇒ Boolean
35 36 37 |
# File 'lib/typesensual/search/results.rb', line 35 def last_page? current_page == total_pages end |
#next_page ⇒ Object
43 44 45 |
# File 'lib/typesensual/search/results.rb', line 43 def next_page current_page + 1 unless last_page? end |
#out_of ⇒ Object
23 24 25 |
# File 'lib/typesensual/search/results.rb', line 23 def out_of @results['out_of'] end |
#per_page ⇒ Object
47 48 49 |
# File 'lib/typesensual/search/results.rb', line 47 def per_page @results['request_params']['per_page'].to_i end |
#prev_page ⇒ Object
39 40 41 |
# File 'lib/typesensual/search/results.rb', line 39 def prev_page current_page - 1 unless first_page? end |
#search_time_ms ⇒ Object
51 52 53 |
# File 'lib/typesensual/search/results.rb', line 51 def search_time_ms @results['search_time_ms'] end |
#total_pages ⇒ Object
55 56 57 |
# File 'lib/typesensual/search/results.rb', line 55 def total_pages (@results['found'] / per_page.to_f).ceil end |