Skip to content

Commit ce08c52

Browse files
committed
[MODEL] Added information about pagination support into the README
1 parent 50ddcb3 commit ce08c52

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

elasticsearch-model/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,25 @@ response.records.each_with_hit { |record, hit| puts "* #{record.title}: #{hit._s
243243
# * Fast black dogs: 0.02250402
244244
```
245245

246-
#### Searching with the Elasticsearch DSL
246+
#### Pagination
247+
248+
You can implement pagination with the `from` and `size` search parameters. However, search results
249+
can be automatically paginated with the [Kaminari](https://github.com/amatsuda/kaminari) gem.
250+
251+
If Kaminari is loaded, use the familiar paging methods:
252+
253+
```ruby
254+
response.page(2).results
255+
response.page(2).records
256+
```
257+
258+
In a Rails controller, use the the `params[:page]` parameter to paginate through results:
259+
260+
```ruby
261+
@articles = Article.search(params[:q]).page(params[:page]).records
262+
```
263+
264+
#### The Elasticsearch DSL
247265

248266
In most situation, you'll want to pass the search definition
249267
in the Elasticsearch [domain-specific language](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html) to the client:

elasticsearch-model/lib/elasticsearch/model/response/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Base
88

99
# @param klass [Class] The name of the model class
1010
# @param response [Hash] The full response returned from Elasticsearch client
11-
# @param results [Results] The collection of results
11+
# @param options [Hash] Optional parameters
1212
#
1313
def initialize(klass, response, options={})
1414
@klass = klass

0 commit comments

Comments
 (0)