Class: Queries::FunctionScoreQueryBuilder
- Inherits:
-
QueryBuilder
- Object
- QueryBuilder
- Queries::FunctionScoreQueryBuilder
- Defined in:
- lib/queries/function_score_query_builder.rb
Defined Under Namespace
Classes: FilterFunctionBuilder
Constant Summary collapse
- NAME =
"function_score"
Instance Method Summary collapse
-
#boostmode(combine_function) ⇒ Object
sets the Boost mode for the query.
-
#boostmode_expr ⇒ Object
BOOST MODE ######################### returns the Boost mode for the query.
-
#filter_function(filter_function) ⇒ Object
sets filter function/s to query.
-
#filter_functions_expr ⇒ Object
FILTER FUNCTIONS ########## returns the filters and functions.
-
#initialize(query: nil, score_function: nil, filter_functions: [], boost_mode: nil) ⇒ FunctionScoreQueryBuilder
constructor
@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.
-
#max_boost(value) ⇒ Object
sets max_boost.
-
#max_boost_expr ⇒ Object
MAX BOOST ########## returns max_boost.
-
#min_score(value) ⇒ Object
sets the min score for the query.
-
#min_score_expr ⇒ Object
MIN SCORE ########## returns the min score for the query.
- #query ⇒ Object
-
#query_expr ⇒ Object
Function Query ########## returns query.
-
#score_function_expr ⇒ Object
Score Function ########## returns score_function.
-
#score_mode(score_mode) ⇒ Object
sets the score mode for the query.
-
#score_mode_expr ⇒ Object
SCORE MODE ########## returns the score mode for the query.
Methods inherited from QueryBuilder
Methods included from AttributesReader
Methods included from AbstractQueryBuilder
Constructor Details
#initialize(query: nil, score_function: nil, filter_functions: [], boost_mode: nil) ⇒ FunctionScoreQueryBuilder
@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
18 19 20 21 22 23 24 25 26 |
# 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 |
Instance Method Details
#boostmode(combine_function) ⇒ Object
sets the Boost mode for the query.
60 61 62 63 |
# 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 ⇒ Object
BOOST MODE ######################### returns the Boost mode for the query
56 57 58 |
# File 'lib/queries/function_score_query_builder.rb', line 56 def boostmode_expr return @boostmode end |
#filter_function(filter_function) ⇒ Object
sets filter function/s to query
72 73 74 75 |
# 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 ⇒ Object
FILTER FUNCTIONS ########## returns the filters and functions
68 69 70 |
# File 'lib/queries/function_score_query_builder.rb', line 68 def filter_functions_expr return @filter_functions end |
#max_boost(value) ⇒ Object
sets max_boost
83 84 85 86 87 |
# 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 ⇒ Object
MAX BOOST ########## returns max_boost
79 80 81 |
# File 'lib/queries/function_score_query_builder.rb', line 79 def max_boost_expr return @max_boost end |
#min_score(value) ⇒ Object
sets the min score for the query
108 109 110 111 112 |
# 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 ⇒ Object
MIN SCORE ########## returns the min score for the query
104 105 106 |
# File 'lib/queries/function_score_query_builder.rb', line 104 def min_score_expr return @min_score end |
#query ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 ⇒ Object
Function Query ########## returns query
44 45 46 |
# File 'lib/queries/function_score_query_builder.rb', line 44 def query_expr return @function_query end |
#score_function_expr ⇒ Object
Score Function ########## returns score_function
50 51 52 |
# File 'lib/queries/function_score_query_builder.rb', line 50 def score_function_expr return @score_builder end |
#score_mode(score_mode) ⇒ Object
sets the score mode for the query.
96 97 98 99 |
# 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 ⇒ Object
SCORE MODE ########## returns the score mode for the query.
92 93 94 |
# File 'lib/queries/function_score_query_builder.rb', line 92 def score_mode_expr return @score_mode end |