class Queries::FunctionScoreQueryBuilder::FilterFunctionBuilder

########## Filter Function Builder Class ##########

Function to be associated with an optional filter, meaning it will be executed only for the documents that match the given filter.

Public Class Methods

new(filter: nil, score_function: nil) click to toggle source

@params:

filter: filter to select the documents
weight: weight to be multiplied to function score before combining
score_function: function for scoring matching documents
# File lib/queries/function_score_query_builder.rb, line 129
def initialize filter: nil, score_function: nil
  @filter = filter
  @score_builder = score_function
end

Public Instance Methods

filter_expr() click to toggle source
Filter Query ##########

returns filter query of the given filter function builder object

# File lib/queries/function_score_query_builder.rb, line 145
def filter_expr
  return @filter
end
query() click to toggle source
# File lib/queries/function_score_query_builder.rb, line 134
def query
  query = {}
  query[:filter] = @filter.query if @filter.present?
  query[:weight] = @weight if @weight.present?
  query.merge!(@score_builder.query) if @score_builder.present?
  return query
end
score_function_expr() click to toggle source
Score Function ##########

returns score function of the given filter function builder object

# File lib/queries/function_score_query_builder.rb, line 152
def score_function_expr
  return @score_builder
end
weight(value) click to toggle source

sets the weight for the filter function

# File lib/queries/function_score_query_builder.rb, line 163
def weight value
  @weight = value.to_f
  return self
end
weight_expr() click to toggle source
Multiplicative Weight ##########

returns the weight for the filter function

# File lib/queries/function_score_query_builder.rb, line 159
def weight_expr
  return @weight
end