Commit 82f4a3df520fbef0661dd8a988145a1411984337
1 parent
cfbdd7ac
Exists in
master
and in
21 other branches
Added support for arrays with boost_where - closes #389
Showing
3 changed files
with
5 additions
and
4 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/query.rb
... | ... | @@ -198,7 +198,7 @@ module Searchkick |
198 | 198 | boost_where = boost_where.merge(options[:personalize]) |
199 | 199 | end |
200 | 200 | boost_where.each do |field, value| |
201 | - if value.is_a?(Array) | |
201 | + if value.is_a?(Array) and value.first.is_a?(Hash) | |
202 | 202 | value.each do |value_factor| |
203 | 203 | value, factor = value_factor[:value], value_factor[:factor] |
204 | 204 | custom_filters << custom_filter(field, value, factor) |
... | ... | @@ -538,9 +538,7 @@ module Searchkick |
538 | 538 | |
539 | 539 | def custom_filter(field, value, factor) |
540 | 540 | { |
541 | - filter: { | |
542 | - term: {field => value} | |
543 | - }, | |
541 | + filter: term_filters(field, value), | |
544 | 542 | boost_factor: factor |
545 | 543 | } |
546 | 544 | end | ... | ... |
test/boost_test.rb
... | ... | @@ -108,7 +108,9 @@ class TestBoost < Minitest::Test |
108 | 108 | {name: "Tomato C", user_ids: [3]} |
109 | 109 | ] |
110 | 110 | assert_first "tomato", "Tomato B", boost_where: {user_ids: 2} |
111 | + assert_first "tomato", "Tomato B", boost_where: {user_ids: [1, 4]} | |
111 | 112 | assert_first "tomato", "Tomato B", boost_where: {user_ids: {value: 2, factor: 10}} |
113 | + assert_first "tomato", "Tomato B", boost_where: {user_ids: {value: [1, 4], factor: 10}} | |
112 | 114 | assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_where: {user_ids: [{value: 1, factor: 10}, {value: 3, factor: 20}]} |
113 | 115 | end |
114 | 116 | ... | ... |