Skip to content

Instantly share code, notes, and snippets.

@lazaronixon
Last active May 17, 2022 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazaronixon/193abbd7bd104680bb52fdab6e955aeb to your computer and use it in GitHub Desktop.
Save lazaronixon/193abbd7bd104680bb52fdab6e955aeb to your computer and use it in GitHub Desktop.
Elasticsearch integrated with geared pagination
module ElasticsearchPaginator
def limit(value)
search.definition.update(size: value); self
end
def offset(value)
search.definition.update(from: value); self
end
def count
results.total
end
def unscope(value)
self
end
end
Elasticsearch::Model::Response::Response.__send__ :include, ElasticsearchPaginator
# Search
gem "elasticsearch-model", "~> 7.1.0"
gem "elasticsearch-rails", "~> 7.1.0"
gem "geared_pagination"
class PhysiciansController < ApplicationController
def index
@results = set_page_and_extract_portion_from(Physician.search(params[:name]))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment