Commit a7b7908f037ff550e525c5e10a827a2f910aa4f1

Authored by Andrew Kane
1 parent 28007e3d

Added body_options and request params

Showing 2 changed files with 24 additions and 0 deletions   Show diff stats
lib/searchkick/relation.rb
@@ -276,6 +276,24 @@ module Searchkick @@ -276,6 +276,24 @@ module Searchkick
276 self 276 self
277 end 277 end
278 278
  279 + def body_options(value)
  280 + spawn.body_options!(value)
  281 + end
  282 +
  283 + def body_options!(value)
  284 + options[:body_options] = value
  285 + self
  286 + end
  287 +
  288 + def request_params(value)
  289 + spawn.request_params!(value)
  290 + end
  291 +
  292 + def request_params!(value)
  293 + options[:request_params] = value
  294 + self
  295 + end
  296 +
279 # same as Active Record 297 # same as Active Record
280 def inspect 298 def inspect
281 entries = results.first(11).map!(&:inspect) 299 entries = results.first(11).map!(&:inspect)
test/query_test.rb
@@ -14,6 +14,11 @@ class QueryTest < Minitest::Test @@ -14,6 +14,11 @@ class QueryTest < Minitest::Test
14 assert_search "milk", ["Milk", "Milk2"], body_options: {min_score: 0.0001} 14 assert_search "milk", ["Milk", "Milk2"], body_options: {min_score: 0.0001}
15 end 15 end
16 16
  17 + def test_body_options
  18 + store_names ["Milk", "Milk2"]
  19 + assert_search_relation ["Milk", "Milk2"], Product.search("milk", relation: true).body_options(min_score: 0.0001)
  20 + end
  21 +
17 def test_default_timeout 22 def test_default_timeout
18 assert_equal "6s", Product.search("*", execute: false).body[:timeout] 23 assert_equal "6s", Product.search("*", execute: false).body[:timeout]
19 end 24 end
@@ -24,6 +29,7 @@ class QueryTest < Minitest::Test @@ -24,6 +29,7 @@ class QueryTest < Minitest::Test
24 29
25 def test_request_params 30 def test_request_params
26 assert_equal "dfs_query_then_fetch", Product.search("*", request_params: {search_type: "dfs_query_then_fetch"}, execute: false).params[:search_type] 31 assert_equal "dfs_query_then_fetch", Product.search("*", request_params: {search_type: "dfs_query_then_fetch"}, execute: false).params[:search_type]
  32 + assert_equal "dfs_query_then_fetch", Product.search("*", relation: true).request_params(search_type: "dfs_query_then_fetch").query.params[:search_type]
27 end 33 end
28 34
29 def test_debug 35 def test_debug