From a7b7908f037ff550e525c5e10a827a2f910aa4f1 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 17 Mar 2020 21:40:51 -0700 Subject: [PATCH] Added body_options and request params --- lib/searchkick/relation.rb | 18 ++++++++++++++++++ test/query_test.rb | 6 ++++++ 2 files changed, 24 insertions(+), 0 deletions(-) diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index 2846a8f..cd5622f 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -276,6 +276,24 @@ module Searchkick self end + def body_options(value) + spawn.body_options!(value) + end + + def body_options!(value) + options[:body_options] = value + self + end + + def request_params(value) + spawn.request_params!(value) + end + + def request_params!(value) + options[:request_params] = value + self + end + # same as Active Record def inspect entries = results.first(11).map!(&:inspect) diff --git a/test/query_test.rb b/test/query_test.rb index 29d214c..c07c007 100644 --- a/test/query_test.rb +++ b/test/query_test.rb @@ -14,6 +14,11 @@ class QueryTest < Minitest::Test assert_search "milk", ["Milk", "Milk2"], body_options: {min_score: 0.0001} end + def test_body_options + store_names ["Milk", "Milk2"] + assert_search_relation ["Milk", "Milk2"], Product.search("milk", relation: true).body_options(min_score: 0.0001) + end + def test_default_timeout assert_equal "6s", Product.search("*", execute: false).body[:timeout] end @@ -24,6 +29,7 @@ class QueryTest < Minitest::Test def test_request_params assert_equal "dfs_query_then_fetch", Product.search("*", request_params: {search_type: "dfs_query_then_fetch"}, execute: false).params[:search_type] + assert_equal "dfs_query_then_fetch", Product.search("*", relation: true).request_params(search_type: "dfs_query_then_fetch").query.params[:search_type] end def test_debug -- libgit2 0.21.0