Commit 3b628b0d11271340b65d519ce8424fce092951db
1 parent
4ca16ca4
Exists in
master
and in
19 other branches
Added missing option for boost_by
Showing
3 changed files
with
12 additions
and
16 deletions
Show diff stats
CHANGELOG.md
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | - Added global `index_prefix` option |
5 | 5 | - Added `wait` option to async reindex |
6 | 6 | - Added `model_includes` option |
7 | +- Added `missing` option for `boost_by` | |
7 | 8 | - Raise error for `reindex_status` when Redis not configured |
8 | 9 | - Warn when incompatible options used with `body` option |
9 | 10 | - Fixed bug where `routing` and `type` options were silently ignored with `body` option | ... | ... |
lib/searchkick/query.rb
... | ... | @@ -883,21 +883,21 @@ module Searchkick |
883 | 883 | } |
884 | 884 | } |
885 | 885 | |
886 | - if value[:missing].present? | |
886 | + if value[:missing] | |
887 | 887 | if below50? |
888 | - raise ArgumentError, "Option 'missing' for boost_by supported in Elasticsearch 5 or greater" | |
888 | + raise ArgumentError, "The missing option for boost_by is not supported in Elasticsearch < 5" | |
889 | 889 | else |
890 | - script_score[:field_value_factor].merge!({missing: value[:missing].to_f}) | |
890 | + script_score[:field_value_factor][:missing] = value[:missing].to_f | |
891 | 891 | end |
892 | - end | |
893 | - | |
894 | - { | |
895 | - filter: { | |
892 | + else | |
893 | + script_score[:filter] = { | |
896 | 894 | exists: { |
897 | 895 | field: field |
898 | 896 | } |
899 | 897 | } |
900 | - }.merge(script_score) | |
898 | + end | |
899 | + | |
900 | + script_score | |
901 | 901 | end |
902 | 902 | end |
903 | 903 | ... | ... |
test/boost_test.rb
... | ... | @@ -116,23 +116,18 @@ class BoostTest < Minitest::Test |
116 | 116 | assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: {orders_count: {factor: 10}} |
117 | 117 | end |
118 | 118 | |
119 | - def test_boost_by_missing_field | |
119 | + def test_boost_by_missing | |
120 | 120 | store [ |
121 | 121 | {name: "Tomato A"}, |
122 | 122 | {name: "Tomato B", orders_count: 10}, |
123 | - {name: "Tomato C", orders_count: 100} | |
124 | 123 | ] |
125 | 124 | |
126 | - assert_raises(Searchkick::InvalidQueryError) do | |
127 | - assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: {orders_count: {factor: 5}, orders_value: {factor: 5}} | |
128 | - end | |
129 | - | |
130 | 125 | if elasticsearch_below50? |
131 | 126 | assert_raises(ArgumentError) do |
132 | - assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: {orders_count: {factor: 5}, orders_value: {factor: 5, missing: 1}} | |
127 | + assert_order "tomato", ["Tomato A", "Tomato B"], boost_by: {orders_count: {missing: 100}} | |
133 | 128 | end |
134 | 129 | else |
135 | - assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: {orders_count: {factor: 5}, orders_value: {factor: 5, missing: 1}} | |
130 | + assert_order "tomato", ["Tomato A", "Tomato B"], boost_by: {orders_count: {missing: 100}} | |
136 | 131 | end |
137 | 132 | end |
138 | 133 | ... | ... |