Class: OpenSearch::DSL::Search::Search
- Inherits:
-
Object
- Object
- OpenSearch::DSL::Search::Search
- Defined in:
- lib/opensearch/dsl/search.rb
Overview
Wraps the whole search definition (queries, filters, aggregations, sorting, etc)
Instance Attribute Summary collapse
-
#aggregations ⇒ Object
Returns the value of attribute aggregations.
-
#sort(*args, &block) ⇒ self
DSL method for building the ‘sort` part of a search definition.
-
#suggest(*args, &block) ⇒ self
DSL method for building the ‘suggest` part of a search definition.
Instance Method Summary collapse
-
#aggregation(*args, &block) ⇒ self
DSL method for building the ‘aggregations` part of a search definition.
-
#filter(*args, &block) ⇒ self
DSL method for building the ‘filter` part of a search definition.
-
#filter=(value) ⇒ Object
Set the filter part of a search definition.
-
#from(value = nil) ⇒ self
(also: #from=)
DSL method for building the ‘from` part of a search definition.
-
#highlight(*args, &block) ⇒ self
DSL method for building the ‘highlight` part of a search definition.
-
#initialize(*args, &block) ⇒ Search
constructor
A new instance of Search.
-
#method_missing(name, *args, &block) ⇒ Object
Delegates to the methods provided by the Options class.
-
#post_filter(*args, &block) ⇒ self
DSL method for building the ‘post_filter` part of a search definition.
-
#post_filter=(value) ⇒ Object
Set the post_filter part of a search definition.
-
#query(*args, &block) ⇒ self, {Query}
DSL method for building or accessing the ‘query` part of a search definition.
-
#query=(value) ⇒ Object
Set the query part of a search definition.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#size(value = nil) ⇒ self
(also: #size=)
DSL method for building the ‘size` part of a search definition.
-
#stored_fields(value = nil) ⇒ self
(also: #stored_fields=)
DSL method for building the ‘stored_fields` part of a search definition.
-
#to_hash ⇒ Hash
Converts the search definition to a Hash.
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Delegates to the methods provided by the Options class
246 247 248 249 250 |
# File 'lib/opensearch/dsl/search.rb', line 246 def method_missing(name, *args, &block) return super unless @options.respond_to? name @options.__send__ name, *args, &block self end |
Instance Attribute Details
#aggregations ⇒ Object
Returns the value of attribute aggregations.
63 64 65 |
# File 'lib/opensearch/dsl/search.rb', line 63 def aggregations @aggregations end |
#sort(*args, &block) ⇒ self
DSL method for building the ‘sort` part of a search definition
173 174 175 176 177 178 179 180 |
# File 'lib/opensearch/dsl/search.rb', line 173 def sort(*args, &block) if !args.empty? || block @sort = Sort.new(*args, &block) self else @sort end end |
#suggest(*args, &block) ⇒ self
DSL method for building the ‘suggest` part of a search definition
229 230 231 232 233 234 235 236 237 238 |
# File 'lib/opensearch/dsl/search.rb', line 229 def suggest(*args, &block) if !args.empty? || block @suggest ||= {} key, = args @suggest.update key => Suggest.new(key, , &block) self else @suggest end end |
Instance Method Details
#aggregation(*args, &block) ⇒ self
DSL method for building the ‘aggregations` part of a search definition
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/opensearch/dsl/search.rb', line 141 def aggregation(*args, &block) @aggregations ||= AggregationsCollection.new if block @aggregations.update args.first => Aggregation.new(*args, &block) else name = args.shift @aggregations.update name => args.shift end self end |
#filter(*args, &block) ⇒ self
DSL method for building the ‘filter` part of a search definition
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/opensearch/dsl/search.rb', line 97 def filter(*args, &block) if block @filter = Filter.new(*args, &block) self elsif !args.empty? @filter = args.first self else @filter end end |
#filter=(value) ⇒ Object
Set the filter part of a search definition
111 112 113 |
# File 'lib/opensearch/dsl/search.rb', line 111 def filter=(value) filter value end |
#from(value = nil) ⇒ self Also known as: from=
DSL method for building the ‘from` part of a search definition
216 217 218 219 220 221 222 223 |
# File 'lib/opensearch/dsl/search.rb', line 216 def from(value = nil) if value @from = value self else @from end end |
#highlight(*args, &block) ⇒ self
DSL method for building the ‘highlight` part of a search definition
160 161 162 163 164 165 166 167 |
# File 'lib/opensearch/dsl/search.rb', line 160 def highlight(*args, &block) if !args.empty? || block @highlight = Highlight.new(*args, &block) self else @highlight end end |
#post_filter(*args, &block) ⇒ self
DSL method for building the ‘post_filter` part of a search definition
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/opensearch/dsl/search.rb', line 119 def post_filter(*args, &block) if block @post_filter = Filter.new(*args, &block) self elsif !args.empty? @post_filter = args.first self else @post_filter end end |
#post_filter=(value) ⇒ Object
Set the post_filter part of a search definition
133 134 135 |
# File 'lib/opensearch/dsl/search.rb', line 133 def post_filter=(value) post_filter value end |
#query(*args, &block) ⇒ self, {Query}
DSL method for building or accessing the ‘query` part of a search definition
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/opensearch/dsl/search.rb', line 75 def query(*args, &block) if block @query = Query.new(*args, &block) self elsif !args.empty? @query = args.first self else @query end end |
#query=(value) ⇒ Object
Set the query part of a search definition
89 90 91 |
# File 'lib/opensearch/dsl/search.rb', line 89 def query=(value) query value end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
252 253 254 |
# File 'lib/opensearch/dsl/search.rb', line 252 def respond_to_missing?(method_name, include_private = false) @options.respond_to?(method_name) || super end |
#size(value = nil) ⇒ self Also known as: size=
DSL method for building the ‘size` part of a search definition
203 204 205 206 207 208 209 210 |
# File 'lib/opensearch/dsl/search.rb', line 203 def size(value = nil) if value @size = value self else @size end end |
#stored_fields(value = nil) ⇒ self Also known as: stored_fields=
DSL method for building the ‘stored_fields` part of a search definition
190 191 192 193 194 195 196 197 |
# File 'lib/opensearch/dsl/search.rb', line 190 def stored_fields(value = nil) if value @stored_fields = value self else @stored_fields end end |
#to_hash ⇒ Hash
Converts the search definition to a Hash
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/opensearch/dsl/search.rb', line 260 def to_hash hash = {} hash.update(query: @query.to_hash) if @query hash.update(filter: @filter.to_hash) if @filter hash.update(post_filter: @post_filter.to_hash) if @post_filter if @aggregations hash.update(aggregations: @aggregations.reduce({}) do |sum, item| sum.update item.first => item.last.to_hash end) end hash.update(sort: @sort.to_hash) if @sort hash.update(size: @size) if @size hash.update(stored_fields: @stored_fields) if @stored_fields hash.update(from: @from) if @from hash.update(suggest: @suggest.reduce({}) { |sum, item| sum.update item.last.to_hash }) if @suggest hash.update(highlight: @highlight.to_hash) if @highlight hash.update(@options) unless @options.empty? hash end |