class Queries::FunctionScoreQueryBuilder
Constants
- NAME
Public Class Methods
new(query: nil, score_function: nil, filter_functions: [], boost_mode: nil)
click to toggle source
@params:
query: query that specifies the documents to retrieve filter_functions: function to be associated with an optional filter, meaning it will be executed only for the documents that match the given filter score_mode: how results of individual score functions will be aggregated boost_mode: how the combined result of score functions will influence the final score together with the sub query score max_boost: maximum boost that will be applied by function score min_score: used to exclude documents that do not meet a certain score threshold score_function: function that defines how the documents will be scored
# File lib/queries/function_score_query_builder.rb, line 18 def initialize query: nil, score_function: nil, filter_functions: [], boost_mode: nil @function_query = query @score_builder = score_function @filter_functions = filter_functions @score_mode = nil @boost_mode = boost_mode @max_boost = nil @min_score = nil end
Public Instance Methods
boostmode(combine_function)
click to toggle source
sets the Boost mode for the query.
# File lib/queries/function_score_query_builder.rb, line 60 def boostmode combine_function @boost_mode = combine_function.combine_function return self end
boostmode_expr()
click to toggle source
BOOST MODE #########################
returns the Boost mode for the query
# File lib/queries/function_score_query_builder.rb, line 56 def boostmode_expr return @boostmode end
filter_function(filter_function)
click to toggle source
sets filter function/s to query
# File lib/queries/function_score_query_builder.rb, line 72 def filter_function filter_function @filter_functions.append(filter_function) return self end
filter_functions_expr()
click to toggle source
FILTER FUNCTIONS ##########
returns the filters and functions
# File lib/queries/function_score_query_builder.rb, line 68 def filter_functions_expr return @filter_functions end
max_boost(value)
click to toggle source
sets max_boost
# File lib/queries/function_score_query_builder.rb, line 83 def max_boost value raise "Max Boost cannot be nil value" if value.nil? @max_boost = value.to_f return self end
max_boost_expr()
click to toggle source
MAX BOOST ##########
returns max_boost
# File lib/queries/function_score_query_builder.rb, line 79 def max_boost_expr return @max_boost end
min_score(value)
click to toggle source
sets the min score for the query
# File lib/queries/function_score_query_builder.rb, line 108 def min_score value raise "Min Score cannot be nil value" if value.nil? @min_score = value.to_f return self end
min_score_expr()
click to toggle source
MIN SCORE ##########
returns the min score for the query
# File lib/queries/function_score_query_builder.rb, line 104 def min_score_expr return @min_score end
query()
click to toggle source
# File lib/queries/function_score_query_builder.rb, line 28 def query query = {} fs_query = self.common_query fs_query[:query] = @function_query.query if @function_query.present? fs_query[:functions] = @filter_functions.map{|ff| ff.query} if @filter_functions.present? fs_query[:score_mode] = @score_mode if @score_mode.present? fs_query[:boost_mode] = @boost_mode if @boost_mode.present? fs_query[:max_boost] = @max_boost if @max_boost.present? fs_query[:min_score] = @min_score if @min_score.present? fs_query.merge!(@score_builder.function) query[name.intern] = fs_query return query end
query_expr()
click to toggle source
Function Query ##########
returns query
# File lib/queries/function_score_query_builder.rb, line 44 def query_expr return @function_query end
score_function_expr()
click to toggle source
Score Function ##########
returns score_function
# File lib/queries/function_score_query_builder.rb, line 50 def score_function_expr return @score_builder end
score_mode(score_mode)
click to toggle source
sets the score mode for the query.
# File lib/queries/function_score_query_builder.rb, line 96 def score_mode score_mode @score_mode = score_mode.score_mode return self end
score_mode_expr()
click to toggle source
SCORE MODE ##########
returns the score mode for the query.
# File lib/queries/function_score_query_builder.rb, line 92 def score_mode_expr return @score_mode end