Completed
Push — master ( 96ab8a...466607 )
by Nicolas
03:10
created

Query   D

Complexity

Total Complexity 35

Size/Duplication

Total Lines 458
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 28

Importance

Changes 0
Metric Value
wmc 35
lcom 0
cbo 28
dl 0
loc 458
rs 4.5
c 0
b 0
f 0

35 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 4 1
A match() 0 4 1
A multi_match() 0 4 1
A bool() 0 4 1
A boosting() 0 4 1
A common_terms() 0 4 1
A constant_score() 0 4 1
A dis_max() 0 4 1
A function_score() 0 4 1
A fuzzy() 0 4 1
A geo_shape() 0 4 1
A has_child() 0 4 1
A has_parent() 0 4 1
A ids() 0 4 1
A match_all() 0 4 1
A more_like_this() 0 4 1
A nested() 0 4 1
A prefix() 0 4 1
A query_string() 0 4 1
A simple_query_string() 0 4 1
A range() 0 4 1
A regexp() 0 4 1
A span_first() 0 4 1
A span_multi_term() 0 4 1
A span_near() 0 4 1
A span_not() 0 4 1
A span_or() 0 4 1
A span_term() 0 4 1
A term() 0 4 1
A terms() 0 4 1
A wildcard() 0 4 1
A geo_distance() 0 4 1
A exists() 0 4 1
A type() 0 4 1
A percolate() 0 4 1
1
<?php
2
namespace Elastica\QueryBuilder\DSL;
3
4
use Elastica\Exception\NotImplementedException;
5
use Elastica\Query\BoolQuery;
6
use Elastica\Query\Boosting;
7
use Elastica\Query\Common;
8
use Elastica\Query\ConstantScore;
9
use Elastica\Query\DisMax;
10
use Elastica\Query\Exists;
11
use Elastica\Query\FunctionScore;
12
use Elastica\Query\Fuzzy;
13
use Elastica\Query\GeoDistance;
14
use Elastica\Query\HasChild;
15
use Elastica\Query\HasParent;
16
use Elastica\Query\Ids;
17
use Elastica\Query\Match;
18
use Elastica\Query\MatchAll;
19
use Elastica\Query\MoreLikeThis;
20
use Elastica\Query\MultiMatch;
21
use Elastica\Query\Nested;
22
use Elastica\Query\Percolate;
23
use Elastica\Query\Prefix;
24
use Elastica\Query\QueryString;
25
use Elastica\Query\Range;
26
use Elastica\Query\Regexp;
27
use Elastica\Query\SimpleQueryString;
28
use Elastica\Query\Term;
29
use Elastica\Query\Terms;
30
use Elastica\Query\Type;
31
use Elastica\Query\Wildcard;
32
use Elastica\QueryBuilder\DSL;
33
34
/**
35
 * elasticsearch query DSL.
36
 *
37
 * @author Manuel Andreo Garcia <[email protected]>
38
 *
39
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-queries.html
40
 */
41
class Query implements DSL
42
{
43
    /**
44
     * must return type for QueryBuilder usage.
45
     *
46
     * @return string
47
     */
48
    public function getType()
49
    {
50
        return self::TYPE_QUERY;
51
    }
52
53
    /**
54
     * match query.
55
     *
56
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
57
     *
58
     * @param string $field
59
     * @param mixed  $values
60
     *
61
     * @return Match
62
     */
63
    public function match($field = null, $values = null)
64
    {
65
        return new Match($field, $values);
66
    }
67
68
    /**
69
     * multi match query.
70
     *
71
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html
72
     *
73
     * @return \Elastica\Query\MultiMatch
74
     */
75
    public function multi_match()
76
    {
77
        return new MultiMatch();
78
    }
79
80
    /**
81
     * bool query.
82
     *
83
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
84
     *
85
     * @return \Elastica\Query\BoolQuery
86
     */
87
    public function bool()
88
    {
89
        return new BoolQuery();
90
    }
91
92
    /**
93
     * boosting query.
94
     *
95
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html
96
     *
97
     * @return Boosting
98
     */
99
    public function boosting()
100
    {
101
        return new Boosting();
102
    }
103
104
    /**
105
     * common terms query.
106
     *
107
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html
108
     *
109
     * @param string $field
110
     * @param string $query
111
     * @param float  $cutoffFrequency percentage in decimal form (.001 == 0.1%)
112
     *
113
     * @return Common
114
     */
115
    public function common_terms($field, $query, $cutoffFrequency)
116
    {
117
        return new Common($field, $query, $cutoffFrequency);
118
    }
119
120
    /**
121
     * constant score query.
122
     *
123
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html
124
     *
125
     * @param null|\Elastica\Query\AbstractQuery|array $filter
126
     *
127
     * @return ConstantScore
128
     */
129
    public function constant_score($filter = null)
130
    {
131
        return new ConstantScore($filter);
0 ignored issues
show
Bug introduced by
It seems like $filter defined by parameter $filter on line 129 can also be of type array; however, Elastica\Query\ConstantScore::__construct() does only seem to accept null|object<Elastica\Query\AbstractQuery>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
132
    }
133
134
    /**
135
     * dis max query.
136
     *
137
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html
138
     *
139
     * @return DisMax
140
     */
141
    public function dis_max()
142
    {
143
        return new DisMax();
144
    }
145
146
    /**
147
     * function score query.
148
     *
149
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html
150
     *
151
     * @return FunctionScore
152
     */
153
    public function function_score()
154
    {
155
        return new FunctionScore();
156
    }
157
158
    /**
159
     * fuzzy query.
160
     *
161
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html
162
     *
163
     * @param string $fieldName Field name
164
     * @param string $value     String to search for
165
     *
166
     * @return Fuzzy
167
     */
168
    public function fuzzy($fieldName = null, $value = null)
169
    {
170
        return new Fuzzy($fieldName, $value);
171
    }
172
173
    /**
174
     * geo shape query.
175
     *
176
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html
177
     */
178
    public function geo_shape()
179
    {
180
        throw new NotImplementedException();
181
    }
182
183
    /**
184
     * has child query.
185
     *
186
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html
187
     *
188
     * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query
189
     * @param string                                               $type  Parent document type
190
     *
191
     * @return HasChild
192
     */
193
    public function has_child($query, $type = null)
194
    {
195
        return new HasChild($query, $type);
196
    }
197
198
    /**
199
     * has parent query.
200
     *
201
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html
202
     *
203
     * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query
204
     * @param string                                               $type  Parent document type
205
     *
206
     * @return HasParent
207
     */
208
    public function has_parent($query, $type)
209
    {
210
        return new HasParent($query, $type);
211
    }
212
213
    /**
214
     * ids query.
215
     *
216
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html
217
     *
218
     * @param array|string|\Elastica\Type $type
219
     * @param array                       $ids
220
     *
221
     * @return Ids
222
     */
223
    public function ids($type = null, array $ids = [])
224
    {
225
        return new Ids($type, $ids);
226
    }
227
228
    /**
229
     * match all query.
230
     *
231
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html
232
     *
233
     * @return MatchAll
234
     */
235
    public function match_all()
236
    {
237
        return new MatchAll();
238
    }
239
240
    /**
241
     * more like this query.
242
     *
243
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html
244
     *
245
     * @return MoreLikeThis
246
     */
247
    public function more_like_this()
248
    {
249
        return new MoreLikeThis();
250
    }
251
252
    /**
253
     * nested query.
254
     *
255
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html
256
     *
257
     * @return Nested
258
     */
259
    public function nested()
260
    {
261
        return new Nested();
262
    }
263
264
    /**
265
     * prefix query.
266
     *
267
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html
268
     *
269
     * @param array $prefix Prefix array
270
     *
271
     * @return Prefix
272
     */
273
    public function prefix(array $prefix = [])
274
    {
275
        return new Prefix($prefix);
276
    }
277
278
    /**
279
     * query string query.
280
     *
281
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
282
     *
283
     * @param string $queryString OPTIONAL Query string for object
284
     *
285
     * @return QueryString
286
     */
287
    public function query_string($queryString = '')
288
    {
289
        return new QueryString($queryString);
290
    }
291
292
    /**
293
     * simple_query_string query.
294
     *
295
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html
296
     *
297
     * @param string $query
298
     * @param array  $fields
299
     *
300
     * @return SimpleQueryString
301
     */
302
    public function simple_query_string($query, array $fields = [])
303
    {
304
        return new SimpleQueryString($query, $fields);
305
    }
306
307
    /**
308
     * range query.
309
     *
310
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
311
     *
312
     * @param string $fieldName
313
     * @param array  $args
314
     *
315
     * @return Range
316
     */
317
    public function range($fieldName = null, array $args = [])
318
    {
319
        return new Range($fieldName, $args);
320
    }
321
322
    /**
323
     * regexp query.
324
     *
325
     * @param string $key
326
     * @param string $value
327
     * @param float  $boost
328
     *
329
     * @return Regexp
330
     *
331
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html
332
     */
333
    public function regexp($key = '', $value = null, $boost = 1.0)
334
    {
335
        return new Regexp($key, $value, $boost);
336
    }
337
338
    /**
339
     * span first query.
340
     *
341
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html
342
     */
343
    public function span_first()
344
    {
345
        throw new NotImplementedException();
346
    }
347
348
    /**
349
     * span multi term query.
350
     *
351
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-multi-term-query.html
352
     */
353
    public function span_multi_term()
354
    {
355
        throw new NotImplementedException();
356
    }
357
358
    /**
359
     * span near query.
360
     *
361
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html
362
     */
363
    public function span_near()
364
    {
365
        throw new NotImplementedException();
366
    }
367
368
    /**
369
     * span not query.
370
     *
371
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-not-query.html
372
     */
373
    public function span_not()
374
    {
375
        throw new NotImplementedException();
376
    }
377
378
    /**
379
     * span or query.
380
     *
381
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-or-query.html
382
     */
383
    public function span_or()
384
    {
385
        throw new NotImplementedException();
386
    }
387
388
    /**
389
     * span term query.
390
     *
391
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-term-query.html
392
     */
393
    public function span_term()
394
    {
395
        throw new NotImplementedException();
396
    }
397
398
    /**
399
     * term query.
400
     *
401
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
402
     *
403
     * @param array $term
404
     *
405
     * @return Term
406
     */
407
    public function term(array $term = [])
408
    {
409
        return new Term($term);
410
    }
411
412
    /**
413
     * terms query.
414
     *
415
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
416
     *
417
     * @param string $key
418
     * @param array  $terms
419
     *
420
     * @return Terms
421
     */
422
    public function terms($key = '', array $terms = [])
423
    {
424
        return new Terms($key, $terms);
425
    }
426
427
    /**
428
     * wildcard query.
429
     *
430
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html
431
     *
432
     * @param string $key   OPTIONAL Wildcard key
433
     * @param string $value OPTIONAL Wildcard value
434
     * @param float  $boost OPTIONAL Boost value (default = 1)
435
     *
436
     * @return Wildcard
437
     */
438
    public function wildcard($key = '', $value = null, $boost = 1.0)
439
    {
440
        return new Wildcard($key, $value, $boost);
441
    }
442
443
    /**
444
     * geo distance query.
445
     *
446
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
447
     *
448
     * @param string       $key
449
     * @param array|string $location
450
     * @param string       $distance
451
     *
452
     * @return GeoDistance
453
     */
454
    public function geo_distance($key, $location, $distance)
455
    {
456
        return new GeoDistance($key, $location, $distance);
457
    }
458
459
    /**
460
     * exists query.
461
     *
462
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
463
     *
464
     * @param string $field
465
     *
466
     * @return Exists
467
     */
468
    public function exists($field)
469
    {
470
        return new Exists($field);
471
    }
472
473
    /**
474
     * type query.
475
     *
476
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-type-query.html
477
     *
478
     * @param string $type Type name
479
     *
480
     * @return Type
481
     */
482
    public function type($type = null)
483
    {
484
        return new Type($type);
485
    }
486
487
    /**
488
     * type query.
489
     *
490
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-percolate-query.html
491
     *
492
     * @return Percolate
493
     */
494
    public function percolate()
495
    {
496
        return new Percolate();
497
    }
498
}
499