Commit def69a7cd06a28a48fec772546b6fe675442618a

Authored by Jordan Anderson
1 parent 7b6be02b

Adds an optional 'missing' param to boost_by

Sets default boost and avoids Searchkick::InvalidQueryError when boosting
an unmapped field
Showing 2 changed files with 8 additions and 0 deletions   Show diff stats
lib/searchkick/query.rb
... ... @@ -872,6 +872,10 @@ module Searchkick
872 872 }
873 873 }
874 874  
  875 + if value[:missing].present?
  876 + script_score[:field_value_factor].merge!({missing: value[:missing].to_f})
  877 + end
  878 +
875 879 {
876 880 filter: {
877 881 exists: {
... ...
test/boost_test.rb
... ... @@ -114,6 +114,10 @@ class BoostTest < Minitest::Test
114 114 ]
115 115 assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: [:orders_count]
116 116 assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: {orders_count: {factor: 10}}
  117 + assert_raises(Searchkick::InvalidQueryError) do
  118 + assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: {orders_count: {factor: 5}, orders_value: {factor: 5}}
  119 + end
  120 + assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: {orders_count: {factor: 5}, orders_value: {factor: 5, missing: 1}}
117 121 end
118 122  
119 123 def test_boost_by_boost_mode_multiply
... ...