The gem adds methods at four layers:
Esse::Index.pagy_search— build a deferred search description.Esse::Cluster#pagy_search— same, for multi-index/cluster searches.Pagy.new_from_esse— build a Pagy instance from an already-executed query.Pagy::Backend#pagy_esse— controller helper that executes the description with pagination.
Esse::Index.pagy_search
Module: Esse::Pagy::IndexSearch (extended into Esse::Index).
.pagy_search(q = nil, **kwargs, &block) → Array
Returns [cluster, self, { q: q, **kwargs }, block] — a description of what to search, not an actual search.
args = UsersIndex.pagy_search(body: { query: { match_all: {} } })# => [UsersIndex.cluster, UsersIndex, { body: {...} }, nil]Alias configurable via Pagy::DEFAULT[:esse_pagy_search] (default: :pagy_search).
Esse::Cluster#pagy_search
Module: Esse::Pagy::ClusterSearch (prepended into Esse::Cluster).
#pagy_search(*indices, **kwargs, &block) → Array
Returns [self, indices, kwargs, block].
Esse.cluster.pagy_search(CitiesIndex, CountiesIndex, body: { ... })Indices can be classes, strings, or wildcard patterns.
Pagy.new_from_esse
Module: Esse::Pagy::ClassMethods (extended into Pagy).
Pagy.new_from_esse(query, vars = {}) → Pagy
Builds a Pagy instance from an already-executed Esse::Search::Query.
query = UsersIndex.search(body: body).limit(10).offset(20)pagy = Pagy.new_from_esse(query)Internally:
vars[:count] = query.response.totalvars[:page] = (query.offset_value / query.limit_value.to_f).ceil + 1vars[:items] = query.limit_valuePagy.new(vars)Pagy::Backend#pagy_esse
Module: Esse::Pagy::Backend (prepended into Pagy::Backend).
#pagy_esse(pagy_search_args, vars = {}) → [Pagy, Esse::Search::Query]
Executes the deferred search with pagination applied.
@pagy, @response = pagy_esse(UsersIndex.pagy_search(body: body), items: 10)Flow:
- Extract
cluster, indices, kwargs, blockfrom the description. - Merge pagination vars with
params(usesPagy::DEFAULT[:page_param]andPagy::DEFAULT[:items]). - Build the query by calling the search method (default
.search, configurable viaPagy::DEFAULT[:esse_search]) and applying.limit(items).offset((page - 1) * items). - Extract total count from
query.response.total. - Construct a
Pagyinstance. - Handle
overflow: :last_pageifPagy::OverflowExtrais loaded. - Return
[pagy, query].
#pagy_esse_get_vars(_query, vars)
Helper: merges Pagy configuration and request params into the vars hash.
| Precedence (high → low) | Source |
|---|---|
Explicit vars[:page] / vars[:items] | caller |
params[page_param], params[:items] | request |
Pagy::DEFAULT[:items] | config |
Pagy configuration keys used
| Key | Default | Purpose |
|---|---|---|
Pagy::DEFAULT[:esse_search] | :search | Name of the search method to call (.search by default) |
Pagy::DEFAULT[:esse_pagy_search] | :pagy_search | Alias name for the deferred-search method |
Pagy::DEFAULT[:items] | Pagy default | Items per page fallback |
Pagy::DEFAULT[:page_param] | :page | Request parameter name for page |
Integration summary
On load:
Esse::Index.extend(Esse::Pagy::IndexSearch)Esse::Cluster.prepend(Esse::Pagy::ClusterSearch)Pagy::Backend.prepend(Esse::Pagy::Backend)Pagy.extend(Esse::Pagy::ClassMethods)No configuration is required beyond whatever Pagy setup you already have.