# Searchkick Extra


Paginate Searchkick::Results objects.

# Synopsis

# Setup

pagy.rb (initializer)
require 'pagy/extras/searchkick'
Searchkick.extend Pagy::Searchkick

# Modes

This extra offers two ways to paginate Searchkick::Results objects:

# Usage

extend Pagy::Searchkick
Controller (pagy_search)
# single model
collection = Article.pagy_search(params[:q])
# multi models
collection = Searchkick.pagy_search(params[:q], models: [Article, Categories])
# paginate it
@pagy, @response = pagy_searchkick(collection, items: 10)

# Usage

Controller (search)
# standard response (already paginated)
@results = Article.search('*', page: 1, per_page: 10, ...)
# get the pagy object out of it
@pagy = Pagy.new_from_searchkick(@results, ...)

# Variables

Variable Description Default
:searchkick_pagy_search customizable name of the pagy search method :pagy_search
:searchkick_search customizable name of the original search method :search

# Methods

This method accepts the same arguments of the search method and you must use it in its place in active mode.

This constructor accepts a Searchkick::Results as the first argument, plus the optional pagy variables. It automatically sets the :items, :page and :count pagy variables extracted/calculated out of it.

This method is similar to the generic pagy method, but specialized for Searchkick. (see the pagy doc)

It expects to receive YourModel.pagy_search(...) result and returns the paginated response.

This sub-method is similar to the pagy_get_vars sub-method, but it is called only by the pagy_searchkick method. (see the pagy_get_vars doc).