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
@@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
4 | - Added `stem_conversions: false` option | 4 | - Added `stem_conversions: false` option |
5 | - Fixed suggestions with partial match boost | 5 | - Fixed suggestions with partial match boost |
6 | - Added support for multiple `boost_where` values on the same field | 6 | - Added support for multiple `boost_where` values on the same field |
7 | +- Added support for array of values for `boost_where` | ||
7 | 8 | ||
8 | ## 0.8.5 | 9 | ## 0.8.5 |
9 | 10 |
lib/searchkick/query.rb
@@ -198,7 +198,7 @@ module Searchkick | @@ -198,7 +198,7 @@ module Searchkick | ||
198 | boost_where = boost_where.merge(options[:personalize]) | 198 | boost_where = boost_where.merge(options[:personalize]) |
199 | end | 199 | end |
200 | boost_where.each do |field, value| | 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 | value.each do |value_factor| | 202 | value.each do |value_factor| |
203 | value, factor = value_factor[:value], value_factor[:factor] | 203 | value, factor = value_factor[:value], value_factor[:factor] |
204 | custom_filters << custom_filter(field, value, factor) | 204 | custom_filters << custom_filter(field, value, factor) |
@@ -538,9 +538,7 @@ module Searchkick | @@ -538,9 +538,7 @@ module Searchkick | ||
538 | 538 | ||
539 | def custom_filter(field, value, factor) | 539 | def custom_filter(field, value, factor) |
540 | { | 540 | { |
541 | - filter: { | ||
542 | - term: {field => value} | ||
543 | - }, | 541 | + filter: term_filters(field, value), |
544 | boost_factor: factor | 542 | boost_factor: factor |
545 | } | 543 | } |
546 | end | 544 | end |
test/boost_test.rb
@@ -108,7 +108,9 @@ class TestBoost < Minitest::Test | @@ -108,7 +108,9 @@ class TestBoost < Minitest::Test | ||
108 | {name: "Tomato C", user_ids: [3]} | 108 | {name: "Tomato C", user_ids: [3]} |
109 | ] | 109 | ] |
110 | assert_first "tomato", "Tomato B", boost_where: {user_ids: 2} | 110 | assert_first "tomato", "Tomato B", boost_where: {user_ids: 2} |
111 | + assert_first "tomato", "Tomato B", boost_where: {user_ids: [1, 4]} | ||
111 | assert_first "tomato", "Tomato B", boost_where: {user_ids: {value: 2, factor: 10}} | 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 | assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_where: {user_ids: [{value: 1, factor: 10}, {value: 3, factor: 20}]} | 114 | assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_where: {user_ids: [{value: 1, factor: 10}, {value: 3, factor: 20}]} |
113 | end | 115 | end |
114 | 116 |