Class: Elastic::Nodes::FunctionScore
- Includes:
- Concerns::Boostable
- Defined in:
- lib/elastic/nodes/function_score.rb
Constant Summary collapse
- SCORE_MODES =
[:multiply, :sum, :avg, :first, :max, :min]
- BOOST_MODES =
[:multiply, :replace, :sum, :avg, :max, :min]
Instance Attribute Summary collapse
-
#boost_mode ⇒ Object
Returns the value of attribute boost_mode.
-
#query ⇒ Object
Returns the value of attribute query.
-
#score_mode ⇒ Object
Returns the value of attribute score_mode.
Attributes included from Concerns::Boostable
Class Method Summary collapse
Instance Method Summary collapse
- #add_decay_function(_field, _options = {}) ⇒ Object
- #add_field_function(_field, factor: 1, modifier: :none, missing: 1, weight: nil, filter: nil) ⇒ Object
- #add_weight_function(_weight, filter: nil) ⇒ Object
- #clone ⇒ Object
- #clone_with_query(_query) ⇒ Object
- #functions=(_values) ⇒ Object
-
#initialize ⇒ FunctionScore
constructor
A new instance of FunctionScore.
- #render(_options = {}) ⇒ Object
- #simplify ⇒ Object
- #traverse(&_block) ⇒ Object
Methods inherited from Base
Methods included from Support::Traversable
Constructor Details
#initialize ⇒ FunctionScore
Returns a new instance of FunctionScore.
15 16 17 |
# File 'lib/elastic/nodes/function_score.rb', line 15 def initialize @functions = [] end |
Instance Attribute Details
#boost_mode ⇒ Object
Returns the value of attribute boost_mode.
13 14 15 |
# File 'lib/elastic/nodes/function_score.rb', line 13 def boost_mode @boost_mode end |
#query ⇒ Object
Returns the value of attribute query.
12 13 14 |
# File 'lib/elastic/nodes/function_score.rb', line 12 def query @query end |
#score_mode ⇒ Object
Returns the value of attribute score_mode.
13 14 15 |
# File 'lib/elastic/nodes/function_score.rb', line 13 def score_mode @score_mode end |
Class Method Details
.build(_query) ⇒ Object
8 9 10 |
# File 'lib/elastic/nodes/function_score.rb', line 8 def self.build(_query) new.tap { |node| node.query = _query } end |
Instance Method Details
#add_decay_function(_field, _options = {}) ⇒ Object
48 49 50 |
# File 'lib/elastic/nodes/function_score.rb', line 48 def add_decay_function(_field, = {}) raise NotImplementedError, 'decay function not implemented' end |
#add_field_function(_field, factor: 1, modifier: :none, missing: 1, weight: nil, filter: nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/elastic/nodes/function_score.rb', line 37 def add_field_function(_field, factor: 1, modifier: :none, missing: 1, weight: nil, filter: nil) params = { 'field' => _field, 'factor' => factor, 'modifier' => modifier, 'missing' => missing } add_function('field_value_factor', params, filter, weight) end |
#add_weight_function(_weight, filter: nil) ⇒ Object
33 34 35 |
# File 'lib/elastic/nodes/function_score.rb', line 33 def add_weight_function(_weight, filter: nil) add_function(nil, nil, filter, _weight) end |
#clone ⇒ Object
75 76 77 |
# File 'lib/elastic/nodes/function_score.rb', line 75 def clone prepare_clone super, @query.clone end |
#clone_with_query(_query) ⇒ Object
79 80 81 |
# File 'lib/elastic/nodes/function_score.rb', line 79 def clone_with_query(_query) prepare_clone super_clone, _query end |
#functions=(_values) ⇒ Object
19 20 21 |
# File 'lib/elastic/nodes/function_score.rb', line 19 def functions=(_values) @functions = _values.dup.to_a end |
#render(_options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/elastic/nodes/function_score.rb', line 57 def render( = {}) hash = { 'query' => @query.render() } hash['boost_mode'] = @boost_mode.to_s if @boost_mode && @boost_mode != :multiply # TODO: add support for the query_path option if @functions.length > 1 hash['score_mode'] = @score_mode.to_s if @score_mode && @score_mode != :multiply hash['functions'] = @functions elsif @functions.length == 1 hash.merge! @functions.first end { 'function_score' => render_boost(hash) } end |
#simplify ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/elastic/nodes/function_score.rb', line 83 def simplify new_query = query.simplify if @functions.empty? return new_query if boost.nil? if new_query.class.include?(Concerns::Boostable) && new_query.boost.nil? new_query.boost = boost return new_query end end prepare_clone(super, new_query) end |
#traverse(&_block) ⇒ Object
52 53 54 55 |
# File 'lib/elastic/nodes/function_score.rb', line 52 def traverse(&_block) super @query.traverse(&_block) end |