Commit 2e3a0b6ea9a4278353d85b87c48aace61e39c0d4
1 parent
5bc7d87d
Exists in
relation
and in
1 other branch
Added boost_where
Showing
3 changed files
with
16 additions
and
0 deletions
Show diff stats
lib/searchkick/relation.rb
... | ... | @@ -182,6 +182,16 @@ module Searchkick |
182 | 182 | self |
183 | 183 | end |
184 | 184 | |
185 | + def boost_where(value) | |
186 | + spawn.boost_where!(value) | |
187 | + end | |
188 | + | |
189 | + # TODO merge options | |
190 | + def boost_where!(value) | |
191 | + options[:boost_where] = value | |
192 | + self | |
193 | + end | |
194 | + | |
185 | 195 | # same as Active Record |
186 | 196 | def inspect |
187 | 197 | entries = results.first(11).map!(&:inspect) | ... | ... |
test/boost_test.rb
... | ... | @@ -149,6 +149,8 @@ class BoostTest < Minitest::Test |
149 | 149 | assert_first "tomato", "Tomato B", boost_where: {user_ids: {value: 2, factor: 10}} |
150 | 150 | assert_first "tomato", "Tomato B", boost_where: {user_ids: {value: [1, 4], factor: 10}} |
151 | 151 | assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_where: {user_ids: [{value: 1, factor: 10}, {value: 3, factor: 20}]} |
152 | + | |
153 | + assert_first_relation "Tomato B", Product.search("tomato", relation: true).boost_where(user_ids: 2) | |
152 | 154 | end |
153 | 155 | |
154 | 156 | def test_boost_where_negative_boost | ... | ... |
test/test_helper.rb
... | ... | @@ -107,6 +107,10 @@ class Minitest::Test |
107 | 107 | assert_equal expected, klass.search(term, **options).map(&:name).first |
108 | 108 | end |
109 | 109 | |
110 | + def assert_first_relation(expected, relation) | |
111 | + assert_equal expected, relation.map(&:name).first | |
112 | + end | |
113 | + | |
110 | 114 | def assert_misspellings(term, expected, misspellings = {}, klass = Product) |
111 | 115 | options = { |
112 | 116 | fields: [:name, :color], | ... | ... |