Class: Solr::Query::Request::Boosting::RecentFieldValueBoostFunction

Inherits:
Object
  • Object
show all
Includes:
Support::SchemaHelper
Defined in:
lib/solr/query/request/boosting/recent_field_value_boost_function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::SchemaHelper

#solarize_field

Constructor Details

#initialize(field:, boost_magnitude:, max_age_days:) ⇒ RecentFieldValueBoostFunction

Returns a new instance of RecentFieldValueBoostFunction.



10
11
12
13
14
15
# File 'lib/solr/query/request/boosting/recent_field_value_boost_function.rb', line 10

def initialize(field:, boost_magnitude:, max_age_days:)
  @field = field
  @boost_magnitude = boost_magnitude
  @max_age_days = max_age_days
  freeze
end

Instance Attribute Details

#boost_magnitudeObject (readonly)

Returns the value of attribute boost_magnitude.



8
9
10
# File 'lib/solr/query/request/boosting/recent_field_value_boost_function.rb', line 8

def boost_magnitude
  @boost_magnitude
end

#fieldObject (readonly)

Returns the value of attribute field.



8
9
10
# File 'lib/solr/query/request/boosting/recent_field_value_boost_function.rb', line 8

def field
  @field
end

#max_age_daysObject (readonly)

Returns the value of attribute max_age_days.



8
9
10
# File 'lib/solr/query/request/boosting/recent_field_value_boost_function.rb', line 8

def max_age_days
  @max_age_days
end

Instance Method Details

#to_solr_sObject



17
18
19
20
21
# File 'lib/solr/query/request/boosting/recent_field_value_boost_function.rb', line 17

def to_solr_s
  solr_field = solarize_field(field)
  recip_max_age_days_ms = 1.0 / (max_age_days * 24 * 3600 * 1000)
  "mul(#{boost_magnitude},recip(ms(NOW,#{solr_field}),#{recip_max_age_days_ms},0.5,0.1))"
end