Class: Stretchy::Builders::BoostBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/stretchy/builders/boost_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBoostBuilder

Returns a new instance of BoostBuilder.



7
8
9
10
11
12
13
# File 'lib/stretchy/builders/boost_builder.rb', line 7

def initialize
  @functions      = []
  @overall_boost  = nil
  @max_boost      = nil
  @score_mode     = 'sum'
  @boost_mode     = 'sum'
end

Instance Attribute Details

#boost_modeObject

Returns the value of attribute boost_mode.



5
6
7
# File 'lib/stretchy/builders/boost_builder.rb', line 5

def boost_mode
  @boost_mode
end

#functionsObject

Returns the value of attribute functions.



5
6
7
# File 'lib/stretchy/builders/boost_builder.rb', line 5

def functions
  @functions
end

#max_boostObject

Returns the value of attribute max_boost.



5
6
7
# File 'lib/stretchy/builders/boost_builder.rb', line 5

def max_boost
  @max_boost
end

#overall_boostObject

Returns the value of attribute overall_boost.



5
6
7
# File 'lib/stretchy/builders/boost_builder.rb', line 5

def overall_boost
  @overall_boost
end

#score_modeObject

Returns the value of attribute score_mode.



5
6
7
# File 'lib/stretchy/builders/boost_builder.rb', line 5

def score_mode
  @score_mode
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/stretchy/builders/boost_builder.rb', line 15

def any?
  @functions.any?
end

#to_search(query_or_filter) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/stretchy/builders/boost_builder.rb', line 19

def to_search(query_or_filter)
  options = { 
    functions:  @functions,
    score_mode: @score_mode,
    boost_mode: @boost_mode
  }
  
  options[:overall_boost] = @overall_boost if @overall_boost
  options[:max_boost]     = @max_boost if @max_boost
  options[:query]         = query_or_filter if query_or_filter.is_a?(Stretchy::Queries::Base)
  options[:filter]        = query_or_filter if query_or_filter.is_a?(Stretchy::Filters::Base)
  
  Stretchy::Queries::FunctionScoreQuery.new(options)
end