Commit e0869bcff7826bd1e70143f62a02aa4679e49f2e

Authored by David Yun
Committed by Andrew Kane
1 parent 0cab6bd9

Add min_score option and tests (#648)

lib/searchkick/query.rb
... ... @@ -392,6 +392,9 @@ module Searchkick
392 392 @routing = options[:routing] if options[:routing]
393 393 end
394 394  
  395 + # merge more body options
  396 + payload = payload.deep_merge(options[:body_options]) if options[:body_options]
  397 +
395 398 @body = payload
396 399 @facet_limits = @facet_limits || {}
397 400 @page = page
... ...
test/query_test.rb
... ... @@ -10,4 +10,14 @@ class QueryTest < Minitest::Test
10 10 assert_equal ["Apple", "Milk"], query.map(&:name).sort
11 11 assert_equal ["Apple", "Milk"], query.execute.map(&:name).sort
12 12 end
  13 +
  14 + def test_with_effective_min_score
  15 + store_names ["Milk", "Milk2"]
  16 + assert_equal ["Milk"], Product.search("Milk", body_options: { min_score: 0.1 }).map(&:name)
  17 + end
  18 +
  19 + def test_with_uneffective_min_score
  20 + store_names ["Milk", "Milk2"]
  21 + assert_equal ["Milk", "Milk2"], Product.search("Milk", body_options: { min_score: 0.0001 }).map(&:name)
  22 + end
13 23 end
... ...
test/sql_test.rb
... ... @@ -52,6 +52,13 @@ class SqlTest < Minitest::Test
52 52 assert_search "product", ["Product"], where: {latitude: {gt: 79}}
53 53 end
54 54  
  55 + # body_options
  56 +
  57 + def test_body_options_should_merge_into_body
  58 + query = Product.search({ query: { name: "milk"}, body_options: { min_score: 1.0 }}, execute: false)
  59 + assert_equal 1.0, query.body[:min_score]
  60 + end
  61 +
55 62 # load
56 63  
57 64 def test_load_default
... ...