Class: Searcher::Boostificator
- Inherits:
-
Object
- Object
- Searcher::Boostificator
- Defined in:
- app/models/searcher/boostificator.rb
Constant Summary collapse
- MILLIS_IN_YEAR =
1000 * 60 * 60 * 24 * 365
- PRECISION =
6
Instance Attribute Summary collapse
-
#a ⇒ Object
Returns the value of attribute a.
-
#b ⇒ Object
Returns the value of attribute b.
-
#boost_field ⇒ Object
Returns the value of attribute boost_field.
-
#boosts ⇒ Object
Returns the value of attribute boosts.
-
#m ⇒ Object
Returns the value of attribute m.
-
#now ⇒ Object
Returns the value of attribute now.
-
#x ⇒ Object
Returns the value of attribute x.
Instance Method Summary collapse
- #adjust_solr_params(searcher) ⇒ Object
-
#initialize(boost_field, options = {}) ⇒ Boostificator
constructor
A new instance of Boostificator.
- #now_ms ⇒ Object
- #now_s ⇒ Object
- #recip ⇒ Object
- #recip_max ⇒ Object
- #recip_min ⇒ Object
- #recip_s ⇒ Object
Constructor Details
#initialize(boost_field, options = {}) ⇒ Boostificator
Returns a new instance of Boostificator.
13 14 15 16 17 18 19 |
# File 'app/models/searcher/boostificator.rb', line 13 def initialize(boost_field, ={}) self.boost_field = boost_field .reverse_merge!(:a => 1.0, :b => 1.0, :m => 1.0 / MILLIS_IN_YEAR) .each do |attribute, value| self.send("#{attribute}=", value) end end |
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a.
7 8 9 |
# File 'app/models/searcher/boostificator.rb', line 7 def a @a end |
#b ⇒ Object
Returns the value of attribute b.
7 8 9 |
# File 'app/models/searcher/boostificator.rb', line 7 def b @b end |
#boost_field ⇒ Object
Returns the value of attribute boost_field.
5 6 7 |
# File 'app/models/searcher/boostificator.rb', line 5 def boost_field @boost_field end |
#boosts ⇒ Object
Returns the value of attribute boosts.
11 12 13 |
# File 'app/models/searcher/boostificator.rb', line 11 def boosts @boosts end |
#m ⇒ Object
Returns the value of attribute m.
7 8 9 |
# File 'app/models/searcher/boostificator.rb', line 7 def m @m end |
#now ⇒ Object
Returns the value of attribute now.
9 10 11 |
# File 'app/models/searcher/boostificator.rb', line 9 def now @now end |
#x ⇒ Object
Returns the value of attribute x.
7 8 9 |
# File 'app/models/searcher/boostificator.rb', line 7 def x @x end |
Instance Method Details
#adjust_solr_params(searcher) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'app/models/searcher/boostificator.rb', line 21 def adjust_solr_params(searcher) searcher.configuration.scope do |sunspot| sunspot.adjust_solr_params do |params| params[:boost] = boosts + [recip_s] params[:defType] = 'edismax' end end end |
#now_ms ⇒ Object
46 47 48 |
# File 'app/models/searcher/boostificator.rb', line 46 def now_ms @now_ms ||= now.to_i * 1000 end |
#now_s ⇒ Object
50 51 52 |
# File 'app/models/searcher/boostificator.rb', line 50 def now_s @now_s ||= now.utc.to_datetime.to_time.iso8601 end |
#recip ⇒ Object
42 43 44 |
# File 'app/models/searcher/boostificator.rb', line 42 def recip @recip ||= a / (m * now_ms + b) end |
#recip_max ⇒ Object
58 59 60 |
# File 'app/models/searcher/boostificator.rb', line 58 def recip_max @recip_max ||= sprintf("%f", (recip * 10**PRECISION).ceil/10.0**PRECISION) end |
#recip_min ⇒ Object
54 55 56 |
# File 'app/models/searcher/boostificator.rb', line 54 def recip_min @recip_min ||= sprintf("%f", (recip * 10**PRECISION).floor/10.0**PRECISION) end |
#recip_s ⇒ Object
34 35 36 |
# File 'app/models/searcher/boostificator.rb', line 34 def recip_s @recip_s ||= "map(recip(abs(ms(#{now_s},#{boost_field})),#{m},#{a},#{b}),#{recip_min},#{recip_max},1)" end |