Commit e0869bcff7826bd1e70143f62a02aa4679e49f2e
Committed by
Andrew Kane
1 parent
0cab6bd9
Exists in
master
and in
21 other branches
Add min_score option and tests (#648)
Showing
3 changed files
with
20 additions
and
0 deletions
Show diff stats
lib/searchkick/query.rb
@@ -392,6 +392,9 @@ module Searchkick | @@ -392,6 +392,9 @@ module Searchkick | ||
392 | @routing = options[:routing] if options[:routing] | 392 | @routing = options[:routing] if options[:routing] |
393 | end | 393 | end |
394 | 394 | ||
395 | + # merge more body options | ||
396 | + payload = payload.deep_merge(options[:body_options]) if options[:body_options] | ||
397 | + | ||
395 | @body = payload | 398 | @body = payload |
396 | @facet_limits = @facet_limits || {} | 399 | @facet_limits = @facet_limits || {} |
397 | @page = page | 400 | @page = page |
test/query_test.rb
@@ -10,4 +10,14 @@ class QueryTest < Minitest::Test | @@ -10,4 +10,14 @@ class QueryTest < Minitest::Test | ||
10 | assert_equal ["Apple", "Milk"], query.map(&:name).sort | 10 | assert_equal ["Apple", "Milk"], query.map(&:name).sort |
11 | assert_equal ["Apple", "Milk"], query.execute.map(&:name).sort | 11 | assert_equal ["Apple", "Milk"], query.execute.map(&:name).sort |
12 | end | 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 | end | 23 | end |
test/sql_test.rb
@@ -52,6 +52,13 @@ class SqlTest < Minitest::Test | @@ -52,6 +52,13 @@ class SqlTest < Minitest::Test | ||
52 | assert_search "product", ["Product"], where: {latitude: {gt: 79}} | 52 | assert_search "product", ["Product"], where: {latitude: {gt: 79}} |
53 | end | 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 | # load | 62 | # load |
56 | 63 | ||
57 | def test_load_default | 64 | def test_load_default |