Last active
May 17, 2022 04:57
-
-
Save lazaronixon/193abbd7bd104680bb52fdab6e955aeb to your computer and use it in GitHub Desktop.
Elasticsearch integrated with geared pagination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Search | |
gem "elasticsearch-model", "~> 7.1.0" | |
gem "elasticsearch-rails", "~> 7.1.0" | |
gem "geared_pagination" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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