class Elasticsearch::DSL::Search::Queries::FunctionScore
A query which allows to modify the score of documents matching the query, either via built-in functions or a custom script
@example Find documents with specific amenities, boosting documents within a certain
price range and geogprahical location search do query do function_score do filter do terms amenities: ['wifi', 'pets'] end functions << { gauss: { price: { origin: 100, scale: 200 } } } functions << { gauss: { location: { origin: '50.090223,14.399590', scale: '5km' } } } end end end
@see www.elastic.co/guide/en/elasticsearch/guide/current/function-score-query.html
Public Class Methods
new(*args, &block)
click to toggle source
Calls superclass method
Elasticsearch::DSL::Search::BaseComponent::new
# File lib/elasticsearch/dsl/search/queries/function_score.rb, line 53 def initialize(*args, &block) super @functions = [] end
Public Instance Methods
filter(*args, &block)
click to toggle source
DSL
method for building the `filter` part of the query definition
@return [self]
# File lib/elasticsearch/dsl/search/queries/function_score.rb, line 71 def filter(*args, &block) @filter = block ? Filter.new(*args, &block) : args.first self end
functions(value=nil)
click to toggle source
DSL
method for building the `functions` part of the query definition
@return [Array]
# File lib/elasticsearch/dsl/search/queries/function_score.rb, line 80 def functions(value=nil) if value @functions = value else @functions end end
functions=(value)
click to toggle source
Set the `functions` part of the query definition
@return [Array]
# File lib/elasticsearch/dsl/search/queries/function_score.rb, line 92 def functions=(value) @functions = value end
query(*args, &block)
click to toggle source
DSL
method for building the `query` part of the query definition
@return [self]
# File lib/elasticsearch/dsl/search/queries/function_score.rb, line 62 def query(*args, &block) @query = block ? @query = Query.new(*args, &block) : args.first self end
to_hash()
click to toggle source
Converts the query definition to a Hash
@return [Hash]
Calls superclass method
# File lib/elasticsearch/dsl/search/queries/function_score.rb, line 100 def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query hash[self.name].update(query: _query) end if @filter _filter = @filter.respond_to?(:to_hash) ? @filter.to_hash : @filter hash[self.name].update(filter: _filter) end unless @functions.empty? hash[self.name].update(functions: @functions) end hash end