Commit d791078beff48bcbbd3f2dc921a5fa25a6ae6983

Authored by Andrew Kane
1 parent 2e3a0b6e

Added boost_by_recency

Showing 2 changed files with 11 additions and 0 deletions   Show diff stats
lib/searchkick/relation.rb
... ... @@ -192,6 +192,16 @@ module Searchkick
192 192 self
193 193 end
194 194  
  195 + def boost_by_recency(value)
  196 + spawn.boost_by_recency!(value)
  197 + end
  198 +
  199 + # TODO merge options
  200 + def boost_by_recency!(value)
  201 + options[:boost_by_recency] = value
  202 + self
  203 + end
  204 +
195 205 # same as Active Record
196 206 def inspect
197 207 entries = results.first(11).map!(&:inspect)
... ...
test/boost_test.rb
... ... @@ -169,6 +169,7 @@ class BoostTest < Minitest::Test
169 169 {name: "Article 3", created_at: Time.now}
170 170 ]
171 171 assert_order "article", ["Article 3", "Article 2", "Article 1"], boost_by_recency: {created_at: {scale: "7d", decay: 0.5}}
  172 + assert_order_relation ["Article 3", "Article 2", "Article 1"], Product.search("article", relation: true).boost_by_recency(created_at: {scale: "7d", decay: 0.5})
172 173 end
173 174  
174 175 def test_boost_by_recency_origin
... ...