From b95ead92d5a8cb1ed6e646162a247ba15cb5254a Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 17 Mar 2020 18:02:35 -0700 Subject: [PATCH] Added more operations --- lib/searchkick/relation.rb | 20 +++++++++++++++++++- test/relation_test.rb | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index bbc80a4..4bd5c4c 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -8,7 +8,7 @@ module Searchkick :records, :results, :suggestions, :each_with_hit, :with_details, :aggregations, :aggs, :took, :error, :model_name, :entry_name, :total_count, :total_entries, :current_page, :per_page, :limit_value, :padding, :total_pages, :num_pages, - :offset_value, :offset, :previous_page, :prev_page, :next_page, :first_page?, :last_page?, + :offset_value, :previous_page, :prev_page, :next_page, :first_page?, :last_page?, :out_of_range?, :hits, :response, :to_a, :first, :scroll def initialize(klass, term = "*", **options) @@ -48,6 +48,24 @@ module Searchkick self end + def offset(value) + spawn.offset!(value) + end + + def offset!(value) + options[:offset] = value + self + end + + def order(*args) + spawn.order!(*args) + end + + def order!(*args) + options[:order] = Array(options[:order]) + args + self + end + # same as Active Record def inspect entries = results.first(11).map!(&:inspect) diff --git a/test/relation_test.rb b/test/relation_test.rb index fa54667..d541437 100644 --- a/test/relation_test.rb +++ b/test/relation_test.rb @@ -3,7 +3,7 @@ require_relative "test_helper" class RelationTest < Minitest::Test def test_works store_names ["Product A", "Product B"] - relation = Product.search("product", relation: true).where(name: "Product A").limit(1) + relation = Product.search("product", relation: true).where(name: "Product A").limit(1).offset(0).order(name: :desc) assert_equal ["Product A"], relation.map(&:name) end -- libgit2 0.21.0