Back to Pagy

Searchkick

docs/toolbox/paginators/searchkick.md

43.5.31.4 KB
Original Source

:icon-search:  :searchkick


:searchkick is a SEARCH paginator for Searchkick::Results objects.

=== :icon-list-ordered:  Setup

ruby
Searchkick.extend Pagy::Search

=== :icon-tools:  Usage

+++ Active mode

!!!success Pagy searches and paginates Use the pagy_search method instead of the search method. !!!

ruby
extend Pagy::Search
ruby
# Single model
search = Article.pagy_search(params[:q])
# Multi models
search = Searchkick.pagy_search(params[:q], models: [Article, Categories])
# Paginate it
@pagy, @response = pagy(:searchkick, search, **options)

+++ Passive mode

!!!success You search and paginate Pagy creates its object out of your result. !!!

ruby
# Standard results (already paginated)
@results = Article.search('*', page: 1, per_page: 10, ...)
# Get the pagy object out of it
@pagy = pagy(:searchkick, @results, **options)

+++

!!! Search paginators don't query a DB, but use the same positional technique as :offset paginators, with shared options and readers. !!!

==- :icon-sliders:  Options

search_method: :my_search : Customize the name of the searchkick method to use (default :search).

{{ include "options/paginator" }}

==- :icon-mention:  Readers

{{ include "snippets/offset-readers" }}

===