diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index 95addb8..2846a8f 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -254,12 +254,12 @@ module Searchkick self end - def scroll(value, &block) - spawn.scroll!(value, &block) + def scroll(value = nil, &block) + spawn.scroll!(value = nil, &block) end - def scroll!(value, &block) - options[:scroll] = value + def scroll!(value = nil, &block) + options[:scroll] = value if value if block execute.scroll(&block) else @@ -267,6 +267,15 @@ module Searchkick end end + def routing(value) + spawn.routing!(value) + end + + def routing!(value) + options[:routing] = value + self + end + # same as Active Record def inspect entries = results.first(11).map!(&:inspect) @@ -274,6 +283,11 @@ module Searchkick "#<#{self.class.name} [#{entries.join(', ')}]>" end + # private + def query + Query.new(klass, term, options) + end + private def hash_args(old, new) @@ -299,7 +313,7 @@ module Searchkick # TODO reset when ! methods called def execute - @execute ||= Query.new(klass, term, options).execute + @execute ||= query.execute end def spawn diff --git a/test/routing_test.rb b/test/routing_test.rb index f2ec672..b6991d2 100644 --- a/test/routing_test.rb +++ b/test/routing_test.rb @@ -4,6 +4,9 @@ class RoutingTest < Minitest::Test def test_routing_query query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false) assert_equal query.params[:routing], "Dollar Tree" + + query = Store.search("Dollar Tree", relation: true).routing("Dollar Tree").query + assert_equal query.params[:routing], "Dollar Tree" end def test_routing_mappings -- libgit2 0.21.0