Class: Stretchy::Boosts::RandomBoost

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

Constant Summary collapse

DEFAULT_WEIGHT =
1.2

Constants included from Utils::Contract

Utils::Contract::ASSERTIONS, Utils::Contract::DISTANCE_FORMAT

Instance Method Summary collapse

Methods included from Utils::Contract

included, #validate!

Constructor Details

#initialize(seed, weight = DEFAULT_WEIGHT) ⇒ RandomBoost

randomizes order (somewhat) consistently per-user www.elastic.co/guide/en/elasticsearch/guide/current/random-scoring.html



13
14
15
16
17
# File 'lib/stretchy/boosts/random_boost.rb', line 13

def initialize(seed, weight = DEFAULT_WEIGHT)
  @seed   = seed
  @weight = weight
  validate!
end

Instance Method Details

#to_searchObject



19
20
21
22
23
24
25
26
# File 'lib/stretchy/boosts/random_boost.rb', line 19

def to_search
  {
    random_score: {
      seed: @seed
    },
    weight: @weight
  }
end