Commit 5bc7d87d254b0c490a4abac435d4a6d0596a9bb7
1 parent
f5040aa3
Exists in
relation
and in
1 other branch
Added boost_by [skip ci]
Showing
3 changed files
with
15 additions
and
0 deletions
Show diff stats
lib/searchkick/relation.rb
... | ... | @@ -172,6 +172,16 @@ module Searchkick |
172 | 172 | self |
173 | 173 | end |
174 | 174 | |
175 | + # TODO support boost_by(:order, :other) | |
176 | + def boost_by(value) | |
177 | + spawn.boost_by!(value) | |
178 | + end | |
179 | + | |
180 | + def boost_by!(value) | |
181 | + options[:boost_by] = value | |
182 | + self | |
183 | + end | |
184 | + | |
175 | 185 | # same as Active Record |
176 | 186 | def inspect |
177 | 187 | entries = results.first(11).map!(&:inspect) | ... | ... |
test/boost_test.rb
... | ... | @@ -115,6 +115,7 @@ class BoostTest < Minitest::Test |
115 | 115 | ] |
116 | 116 | assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: [:orders_count] |
117 | 117 | assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: {orders_count: {factor: 10}} |
118 | + assert_order_relation ["Tomato C", "Tomato B", "Tomato A"], Product.search("tomato", relation: true).boost_by(orders_count: {factor: 10}) | |
118 | 119 | end |
119 | 120 | |
120 | 121 | def test_boost_by_missing | ... | ... |
test/test_helper.rb
... | ... | @@ -95,6 +95,10 @@ class Minitest::Test |
95 | 95 | assert_equal expected, klass.search(term, **options).map(&:name) |
96 | 96 | end |
97 | 97 | |
98 | + def assert_order_relation(expected, relation) | |
99 | + assert_equal expected, relation.map(&:name) | |
100 | + end | |
101 | + | |
98 | 102 | def assert_equal_scores(term, options = {}, klass = Product) |
99 | 103 | assert_equal 1, klass.search(term, **options).hits.map { |a| a["_score"] }.uniq.size |
100 | 104 | end | ... | ... |