Module: Pagy::TypesenseRailsPaginator

Defined in:
lib/pagy/toolbox/paginators/typesense_rails.rb

Class Method Summary collapse

Class Method Details

.paginate(search, options) ⇒ Object

Paginate from the search object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pagy/toolbox/paginators/typesense_rails.rb', line 10

def paginate(search, options)
  if search.is_a?(Search::Arguments) # Active mode

    Searcher.wrap(search, options) do
      model, arguments, search_options = search

      search_options[:per_page] = options[:limit]
      search_options[:page]     = options[:page]

      method          = options[:search_method] || TypesenseRails::DEFAULT[:search_method]
      results         = model.send(method, *arguments, search_options)
      options[:count] = results.raw_answer['found']

      [TypesenseRails.new(**options), results]
    end

  else # Passive mode
    options[:limit] = search.raw_answer['request_params']['per_page']
    options[:page]  = search.raw_answer['page']
    options[:count] = search.raw_answer['found']

    TypesenseRails.new(**options)
  end
end