class Elasticband::Query::FunctionScore
Attributes
boost_mode[RW]
function[RW]
query_or_filter[RW]
score_mode[RW]
Public Class Methods
new(query_or_filter, function, score_mode, boost_mode)
click to toggle source
# File lib/elasticband/query/function_score.rb, line 6 def initialize(query_or_filter, function, score_mode, boost_mode) self.query_or_filter = query_or_filter self.function = function self.score_mode = score_mode self.boost_mode = boost_mode end
Public Instance Methods
to_h()
click to toggle source
# File lib/elasticband/query/function_score.rb, line 13 def to_h { function_score: function_score_hash } end
Private Instance Methods
function_hash()
click to toggle source
# File lib/elasticband/query/function_score.rb, line 31 def function_hash if function.is_a?(Enumerable) function.size > 1 ? { functions: function.map(&:to_h) } : single_function_hash(function.first) else single_function_hash(function) end end
function_score_hash()
click to toggle source
# File lib/elasticband/query/function_score.rb, line 19 def function_score_hash query_or_filter_hash.merge!(function_hash).merge(score_mode.to_h).merge(boost_mode.to_h) end
query_or_filter_hash()
click to toggle source
# File lib/elasticband/query/function_score.rb, line 23 def query_or_filter_hash if query_or_filter.is_a?(Query) { query: query_or_filter.to_h } else { filter: query_or_filter.to_h } end end
single_function_hash(function)
click to toggle source
# File lib/elasticband/query/function_score.rb, line 39 def single_function_hash(function) function_hash = function.to_h function_hash.key?(:filter) ? { functions: [function_hash] } : function_hash end