Class: OpenSearch::DSL::Search::Queries::FunctionScore
- Inherits:
-
Object
- Object
- OpenSearch::DSL::Search::Queries::FunctionScore
- Includes:
- BaseComponent
- Defined in:
- lib/opensearch/dsl/search/queries/function_score.rb
Overview
A query which allows to modify the score of documents matching the query, either via built-in functions or a custom script
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
Instance Attribute Summary collapse
-
#functions(value = nil) ⇒ Array
DSL method for building the ‘functions` part of the query definition.
Instance Method Summary collapse
-
#filter(*args, &block) ⇒ self
DSL method for building the ‘filter` part of the query definition.
-
#initialize(*args, &block) ⇒ FunctionScore
constructor
A new instance of FunctionScore.
-
#query(*args, &block) ⇒ self
DSL method for building the ‘query` part of the query definition.
-
#to_hash ⇒ Hash
Converts the query definition to a Hash.
Methods included from BaseComponent
Constructor Details
#initialize(*args, &block) ⇒ FunctionScore
Returns a new instance of FunctionScore.
60 61 62 63 |
# File 'lib/opensearch/dsl/search/queries/function_score.rb', line 60 def initialize(*args, &block) super @functions = [] end |
Instance Attribute Details
#functions(value = nil) ⇒ Array
DSL method for building the ‘functions` part of the query definition
87 88 89 90 91 92 93 |
# File 'lib/opensearch/dsl/search/queries/function_score.rb', line 87 def functions(value = nil) if value @functions = value else @functions end end |
Instance Method Details
#filter(*args, &block) ⇒ self
DSL method for building the ‘filter` part of the query definition
78 79 80 81 |
# File 'lib/opensearch/dsl/search/queries/function_score.rb', line 78 def filter(*args, &block) @filter = block ? Filter.new(*args, &block) : args.first self end |
#query(*args, &block) ⇒ self
DSL method for building the ‘query` part of the query definition
69 70 71 72 |
# File 'lib/opensearch/dsl/search/queries/function_score.rb', line 69 def query(*args, &block) @query = block ? @query = Query.new(*args, &block) : args.first self end |
#to_hash ⇒ Hash
Converts the query definition to a Hash
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/opensearch/dsl/search/queries/function_score.rb', line 105 def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query hash[name].update(query: _query) end if @filter _filter = @filter.respond_to?(:to_hash) ? @filter.to_hash : @filter hash[name].update(filter: _filter) end hash[name].update(functions: @functions) unless @functions.empty? hash end |