Class: Typesensual::Search::Results

Inherits:
Object
  • Object
show all
Defined in:
lib/typesensual/search/results.rb

Instance Method Summary collapse

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

#countObject



19
20
21
# File 'lib/typesensual/search/results.rb', line 19

def count
  @results['found']
end

#current_pageObject



27
28
29
# File 'lib/typesensual/search/results.rb', line 27

def current_page
  @results['page']
end

#facetsObject



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

Returns:

  • (Boolean)


31
32
33
# File 'lib/typesensual/search/results.rb', line 31

def first_page?
  current_page == 1
end

#grouped_hitsObject



15
16
17
# File 'lib/typesensual/search/results.rb', line 15

def grouped_hits
  @results['grouped_hits'].map { |hit| GroupedHit.new(hit) }
end

#hitsObject



11
12
13
# File 'lib/typesensual/search/results.rb', line 11

def hits
  @results['hits'].map { |hit| Hit.new(hit) }
end

#last_page?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/typesensual/search/results.rb', line 35

def last_page?
  current_page == total_pages
end

#next_pageObject



43
44
45
# File 'lib/typesensual/search/results.rb', line 43

def next_page
  current_page + 1 unless last_page?
end

#out_ofObject



23
24
25
# File 'lib/typesensual/search/results.rb', line 23

def out_of
  @results['out_of']
end

#per_pageObject



47
48
49
# File 'lib/typesensual/search/results.rb', line 47

def per_page
  @results['request_params']['per_page'].to_i
end

#prev_pageObject



39
40
41
# File 'lib/typesensual/search/results.rb', line 39

def prev_page
  current_page - 1 unless first_page?
end

#search_time_msObject



51
52
53
# File 'lib/typesensual/search/results.rb', line 51

def search_time_ms
  @results['search_time_ms']
end

#total_pagesObject



55
56
57
# File 'lib/typesensual/search/results.rb', line 55

def total_pages
  (@results['found'] / per_page.to_f).ceil
end