Class: Queries::FunctionScoreQueryBuilder::FilterFunctionBuilder

Inherits:
Object
  • Object
show all
Includes:
AttributesReader
Defined in:
lib/queries/function_score_query_builder.rb

Overview

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

Instance Method Summary collapse

Methods included from AttributesReader

#attributes

Constructor Details

#initialize(filter: nil, score_function: nil) ⇒ FilterFunctionBuilder

@params:

filter: filter to select the documents
weight: weight to be multiplied to function score before combining
score_function: function for scoring matching documents


129
130
131
132
# File 'lib/queries/function_score_query_builder.rb', line 129

def initialize filter: nil, score_function: nil
  @filter = filter
  @score_builder = score_function
end

Instance Method Details

#filter_exprObject

Filter Query ########## returns filter query of the given filter function builder object



145
146
147
# File 'lib/queries/function_score_query_builder.rb', line 145

def filter_expr
  return @filter
end

#queryObject



134
135
136
137
138
139
140
# 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_exprObject

Score Function ########## returns score function of the given filter function builder object



152
153
154
# File 'lib/queries/function_score_query_builder.rb', line 152

def score_function_expr
  return @score_builder
end

#weight(value) ⇒ Object

sets the weight for the filter function



163
164
165
166
# File 'lib/queries/function_score_query_builder.rb', line 163

def weight value
  @weight = value.to_f
  return self
end

#weight_exprObject

Multiplicative Weight ########## returns the weight for the filter function



159
160
161
# File 'lib/queries/function_score_query_builder.rb', line 159

def weight_expr
  return @weight
end