diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index 1618253..7d2ae36 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -172,6 +172,16 @@ module Searchkick self end + # TODO support boost_by(:order, :other) + def boost_by(value) + spawn.boost_by!(value) + end + + def boost_by!(value) + options[:boost_by] = value + self + end + # same as Active Record def inspect entries = results.first(11).map!(&:inspect) diff --git a/test/boost_test.rb b/test/boost_test.rb index 7aa5eab..01a6eb8 100644 --- a/test/boost_test.rb +++ b/test/boost_test.rb @@ -115,6 +115,7 @@ class BoostTest < Minitest::Test ] assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: [:orders_count] assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: {orders_count: {factor: 10}} + assert_order_relation ["Tomato C", "Tomato B", "Tomato A"], Product.search("tomato", relation: true).boost_by(orders_count: {factor: 10}) end def test_boost_by_missing diff --git a/test/test_helper.rb b/test/test_helper.rb index 2fd23fa..cb06959 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -95,6 +95,10 @@ class Minitest::Test assert_equal expected, klass.search(term, **options).map(&:name) end + def assert_order_relation(expected, relation) + assert_equal expected, relation.map(&:name) + end + def assert_equal_scores(term, options = {}, klass = Product) assert_equal 1, klass.search(term, **options).hits.map { |a| a["_score"] }.uniq.size end -- libgit2 0.21.0