Commit 82f4a3df520fbef0661dd8a988145a1411984337

Authored by Andrew Kane
1 parent cfbdd7ac

Added support for arrays with boost_where - closes #389

CHANGELOG.md
... ... @@ -4,6 +4,7 @@
4 4 - Added `stem_conversions: false` option
5 5 - Fixed suggestions with partial match boost
6 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 9 ## 0.8.5
9 10  
... ...
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 &lt; 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  
... ...