Commit b95ead92d5a8cb1ed6e646162a247ba15cb5254a
1 parent
1deac611
Exists in
relation
and in
1 other branch
Added more operations
Showing
2 changed files
with
20 additions
and
2 deletions
Show diff stats
lib/searchkick/relation.rb
... | ... | @@ -8,7 +8,7 @@ module Searchkick |
8 | 8 | :records, :results, :suggestions, :each_with_hit, :with_details, :aggregations, :aggs, |
9 | 9 | :took, :error, :model_name, :entry_name, :total_count, :total_entries, |
10 | 10 | :current_page, :per_page, :limit_value, :padding, :total_pages, :num_pages, |
11 | - :offset_value, :offset, :previous_page, :prev_page, :next_page, :first_page?, :last_page?, | |
11 | + :offset_value, :previous_page, :prev_page, :next_page, :first_page?, :last_page?, | |
12 | 12 | :out_of_range?, :hits, :response, :to_a, :first, :scroll |
13 | 13 | |
14 | 14 | def initialize(klass, term = "*", **options) |
... | ... | @@ -48,6 +48,24 @@ module Searchkick |
48 | 48 | self |
49 | 49 | end |
50 | 50 | |
51 | + def offset(value) | |
52 | + spawn.offset!(value) | |
53 | + end | |
54 | + | |
55 | + def offset!(value) | |
56 | + options[:offset] = value | |
57 | + self | |
58 | + end | |
59 | + | |
60 | + def order(*args) | |
61 | + spawn.order!(*args) | |
62 | + end | |
63 | + | |
64 | + def order!(*args) | |
65 | + options[:order] = Array(options[:order]) + args | |
66 | + self | |
67 | + end | |
68 | + | |
51 | 69 | # same as Active Record |
52 | 70 | def inspect |
53 | 71 | entries = results.first(11).map!(&:inspect) | ... | ... |
test/relation_test.rb
... | ... | @@ -3,7 +3,7 @@ require_relative "test_helper" |
3 | 3 | class RelationTest < Minitest::Test |
4 | 4 | def test_works |
5 | 5 | store_names ["Product A", "Product B"] |
6 | - relation = Product.search("product", relation: true).where(name: "Product A").limit(1) | |
6 | + relation = Product.search("product", relation: true).where(name: "Product A").limit(1).offset(0).order(name: :desc) | |
7 | 7 | assert_equal ["Product A"], relation.map(&:name) |
8 | 8 | end |
9 | 9 | ... | ... |