Module: Elasticsearch::Persistence::QueryMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- Relation
- Defined in:
- lib/elasticsearch/persistence/relation/query_methods.rb
Defined Under Namespace
Classes: WhereChain
Constant Summary collapse
- MULTI_VALUE_METHODS =
[:where, :order, :field, :highlight, :source, :must_not, :should, :query_string, :aggregation, :search_option, :filter, :or_filter, :extending, :skip_callbacks]
- SINGLE_VALUE_METHODS =
[:size]
Instance Method Summary collapse
- #aggregation(name, options = {}, &block) ⇒ Object
- #aggregation!(name, options = {}, &block) ⇒ Object
- #bind(value) ⇒ Object
-
#bind!(value) ⇒ Object
:nodoc:.
- #build_where(opts, other = []) ⇒ Object
- #extending(*modules, &block) ⇒ Object
-
#extending!(*modules, &block) ⇒ Object
:nodoc:.
- #field(*args) ⇒ Object (also: #fields)
- #field!(*args) ⇒ Object
- #filter(name, options = {}, &block) ⇒ Object
- #filter!(name, options = {}, &block) ⇒ Object
- #has_field?(field) ⇒ Boolean
- #highlight(*args) ⇒ Object
- #highlight!(*args) ⇒ Object
- #must_not(opts = :chain, *rest) ⇒ Object (also: #where_not)
- #must_not!(opts, *rest) ⇒ Object
-
#none ⇒ Object
Returns a chainable relation with zero records.
-
#none! ⇒ Object
:nodoc:.
- #or_filter(name, options = {}, &block) ⇒ Object
- #or_filter!(name, options = {}, &block) ⇒ Object
- #order(*args) ⇒ Object (also: #sort)
- #order!(*args) ⇒ Object
- #query_string(opts = :chain, *rest) ⇒ Object
-
#query_string!(opts, *rest) ⇒ Object
:nodoc:.
- #should(opts = :chain, *rest) ⇒ Object
- #should!(opts, *rest) ⇒ Object
- #size(args) ⇒ Object (also: #limit)
- #size!(args) ⇒ Object
- #skip_callbacks(*args) ⇒ Object
- #skip_callbacks!(*args) ⇒ Object
- #source(*args) ⇒ Object
- #source!(*args) ⇒ Object
- #where(opts = :chain, *rest) ⇒ Object (also: #must)
-
#where!(opts, *rest) ⇒ Object
:nodoc:.
Instance Method Details
#aggregation(name, options = {}, &block) ⇒ Object
210 211 212 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 210 def aggregation(name, = {}, &block) spawn.aggregation!(name, , &block) end |
#aggregation!(name, options = {}, &block) ⇒ Object
214 215 216 217 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 214 def aggregation!(name, = {}, &block) self.aggregation_values += [{name: name, args: }] self end |
#bind(value) ⇒ Object
254 255 256 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 254 def bind(value) spawn.bind!(value) end |
#bind!(value) ⇒ Object
:nodoc:
258 259 260 261 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 258 def bind!(value) # :nodoc: self.bind_values += [value] self end |
#build_where(opts, other = []) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 263 def build_where(opts, other = []) case opts when String, Array #TODO: Remove duplication with: /activerecord/lib/active_record/sanitization.rb:113 values = Hash === other.first ? other.first.values : other values.grep(Elasticsearch::Persistence::Relation) do |rel| self.bind_values += rel.bind_values end [other.empty? ? opts : ([opts] + other)] when Hash [other.empty? ? opts : ([opts] + other)] else [opts] end end |
#extending(*modules, &block) ⇒ Object
303 304 305 306 307 308 309 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 303 def extending(*modules, &block) if modules.any? || block spawn.extending!(*modules, &block) else self end end |
#extending!(*modules, &block) ⇒ Object
:nodoc:
311 312 313 314 315 316 317 318 319 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 311 def extending!(*modules, &block) # :nodoc: modules << Module.new(&block) if block modules.flatten! self.extending_values += modules extend(*extending_values) if extending_values.any? self end |
#field(*args) ⇒ Object Also known as: fields
222 223 224 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 222 def field(*args) spawn.field!(*args) end |
#field!(*args) ⇒ Object
227 228 229 230 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 227 def field!(*args) self.field_values += args self end |
#filter(name, options = {}, &block) ⇒ Object
198 199 200 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 198 def filter(name, = {}, &block) spawn.filter!(name, , &block) end |
#filter!(name, options = {}, &block) ⇒ Object
202 203 204 205 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 202 def filter!(name, = {}, &block) self.filter_values += [{name: name, args: }] self end |
#has_field?(field) ⇒ Boolean
247 248 249 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 247 def has_field?(field) spawn.filter(:exists, {field: field}) end |
#highlight(*args) ⇒ Object
281 282 283 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 281 def highlight(*args) spawn.highlight!(*args) end |
#highlight!(*args) ⇒ Object
285 286 287 288 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 285 def highlight!(*args) self.highlight_values += args self end |
#must_not(opts = :chain, *rest) ⇒ Object Also known as: where_not
143 144 145 146 147 148 149 150 151 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 143 def must_not(opts = :chain, *rest) if opts == :chain WhereChain.new(spawn) elsif opts.blank? self else spawn.must_not!(opts, *rest) end end |
#must_not!(opts, *rest) ⇒ Object
155 156 157 158 159 160 161 162 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 155 def must_not!(opts, *rest) if opts == :chain WhereChain.new(self) else self.must_not_values += build_where(opts, rest) self end end |
#none ⇒ Object
Returns a chainable relation with zero records.
294 295 296 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 294 def none extending(NullRelation) end |
#none! ⇒ Object
:nodoc:
298 299 300 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 298 def none! # :nodoc: extending!(NullRelation) end |
#or_filter(name, options = {}, &block) ⇒ Object
187 188 189 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 187 def or_filter(name, = {}, &block) spawn.or_filter!(name, , &block) end |
#or_filter!(name, options = {}, &block) ⇒ Object
191 192 193 194 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 191 def or_filter!(name, = {}, &block) self.or_filter_values += [{name: name, args: }] self end |
#order(*args) ⇒ Object Also known as: sort
54 55 56 57 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 54 def order(*args) check_if_method_has_arguments!(:order, args) spawn.order!(*args) end |
#order!(*args) ⇒ Object
59 60 61 62 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 59 def order!(*args) self.order_values += [preprocess_order_args(args)] self end |
#query_string(opts = :chain, *rest) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 121 def query_string(opts = :chain, *rest) if opts == :chain WhereChain.new(spawn) elsif opts.blank? self else spawn.query_string!(opts, *rest) end end |
#query_string!(opts, *rest) ⇒ Object
:nodoc:
131 132 133 134 135 136 137 138 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 131 def query_string!(opts, *rest) # :nodoc: if opts == :chain WhereChain.new(self) else self.query_string_values += build_where(opts, rest) self end end |
#should(opts = :chain, *rest) ⇒ Object
167 168 169 170 171 172 173 174 175 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 167 def should(opts = :chain, *rest) if opts == :chain WhereChain.new(spawn) elsif opts.blank? self else spawn.should!(opts, *rest) end end |
#should!(opts, *rest) ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 177 def should!(opts, *rest) if opts == :chain WhereChain.new(self) else self.should_values += build_where(opts, rest) self end end |
#size(args) ⇒ Object Also known as: limit
79 80 81 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 79 def size(args) spawn.size!(args) end |
#size!(args) ⇒ Object
83 84 85 86 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 83 def size!(args) self.size_value = args self end |
#skip_callbacks(*args) ⇒ Object
67 68 69 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 67 def skip_callbacks(*args) spawn.skip_callbacks!(*args) end |
#skip_callbacks!(*args) ⇒ Object
71 72 73 74 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 71 def skip_callbacks!(*args) self.skip_callbacks_values += args self end |
#source(*args) ⇒ Object
235 236 237 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 235 def source(*args) spawn.source!(*args) end |
#source!(*args) ⇒ Object
239 240 241 242 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 239 def source!(*args) self.source_values += args self end |
#where(opts = :chain, *rest) ⇒ Object Also known as: must
93 94 95 96 97 98 99 100 101 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 93 def where(opts = :chain, *rest) if opts == :chain WhereChain.new(spawn) elsif opts.blank? self else spawn.where!(opts, *rest) end end |
#where!(opts, *rest) ⇒ Object
:nodoc:
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/elasticsearch/persistence/relation/query_methods.rb', line 105 def where!(opts, *rest) # :nodoc: if opts == :chain WhereChain.new(self) else #if Hash === opts #opts = sanitize_forbidden_attributes(opts) #end self.where_values += build_where(opts, rest) self end end |