Class: Stretchy::Boosts::FieldDecayBoost

Inherits:
Base
  • Object
show all
Defined in:
lib/stretchy/boosts/field_decay_boost.rb

Constant Summary collapse

DEFAULT_DECAY_FN =
:gauss

Constants inherited from Base

Base::DEFAULT_WEIGHT

Instance Method Summary collapse

Methods included from Utils::Validation

#errors, included, #require_one!, #require_only_one!, #valid?, #validate!, #validator

Constructor Details

#initialize(options = {}) ⇒ FieldDecayBoost

Returns a new instance of FieldDecayBoost.



26
27
28
29
30
31
# File 'lib/stretchy/boosts/field_decay_boost.rb', line 26

def initialize(options = {})
  self.class.attribute_set.set(self, options) if options
  set_default_attributes

  validate!
end

Instance Method Details

#to_searchObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/stretchy/boosts/field_decay_boost.rb', line 33

def to_search
  json = {scale: @scale}
  if @origin.is_a?(Types::Base)
    json[:origin] = @origin.to_search
  else
    json[:origin] = @origin
  end
  json[:offset]   = @offset  if @offset
  json[:decay]    = @decay_amount   if @decay_amount

  {
    @decay => {
      @field => json
    },
    weight: @weight
  }
end