Completed
Push — master ( dbdc32...0d10e3 )
by Nicolas
02:23
created

Query::span_within()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
namespace Elastica\QueryBuilder\DSL;
3
4
use Elastica\Exception\NotImplementedException;
5
use Elastica\Query\AbstractSpanQuery;
6
use Elastica\Query\BoolQuery;
7
use Elastica\Query\Boosting;
8
use Elastica\Query\Common;
9
use Elastica\Query\ConstantScore;
10
use Elastica\Query\DisMax;
11
use Elastica\Query\Exists;
12
use Elastica\Query\FunctionScore;
13
use Elastica\Query\Fuzzy;
14
use Elastica\Query\GeoDistance;
15
use Elastica\Query\HasChild;
16
use Elastica\Query\HasParent;
17
use Elastica\Query\Ids;
18
use Elastica\Query\Match;
19
use Elastica\Query\MatchAll;
20
use Elastica\Query\MatchNone;
21
use Elastica\Query\MoreLikeThis;
22
use Elastica\Query\MultiMatch;
23
use Elastica\Query\Nested;
24
use Elastica\Query\Percolate;
25
use Elastica\Query\Prefix;
26
use Elastica\Query\QueryString;
27
use Elastica\Query\Range;
28
use Elastica\Query\Regexp;
29
use Elastica\Query\SimpleQueryString;
30
use Elastica\Query\SpanContaining;
31
use Elastica\Query\SpanFirst;
32
use Elastica\Query\SpanMulti;
33
use Elastica\Query\SpanNear;
34
use Elastica\Query\SpanNot;
35
use Elastica\Query\SpanOr;
36
use Elastica\Query\SpanTerm;
37
use Elastica\Query\SpanWithin;
38
use Elastica\Query\Term;
39
use Elastica\Query\Terms;
40
use Elastica\Query\Type;
41
use Elastica\Query\Wildcard;
42
use Elastica\QueryBuilder\DSL;
43
44
/**
45
 * elasticsearch query DSL.
46
 *
47
 * @author Manuel Andreo Garcia <[email protected]>
48
 *
49
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-queries.html
50
 */
51
class Query implements DSL
52
{
53
    /**
54
     * must return type for QueryBuilder usage.
55
     *
56
     * @return string
57
     */
58
    public function getType()
59
    {
60
        return self::TYPE_QUERY;
61
    }
62
63
    /**
64
     * match query.
65
     *
66
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
67
     *
68
     * @param string $field
69
     * @param mixed  $values
70
     *
71
     * @return Match
72
     */
73
    public function match($field = null, $values = null)
74
    {
75
        return new Match($field, $values);
76
    }
77
78
    /**
79
     * multi match query.
80
     *
81
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html
82
     *
83
     * @return \Elastica\Query\MultiMatch
84
     */
85
    public function multi_match()
86
    {
87
        return new MultiMatch();
88
    }
89
90
    /**
91
     * bool query.
92
     *
93
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
94
     *
95
     * @return \Elastica\Query\BoolQuery
96
     */
97
    public function bool()
98
    {
99
        return new BoolQuery();
100
    }
101
102
    /**
103
     * boosting query.
104
     *
105
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html
106
     *
107
     * @return Boosting
108
     */
109
    public function boosting()
110
    {
111
        return new Boosting();
112
    }
113
114
    /**
115
     * common terms query.
116
     *
117
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html
118
     *
119
     * @param string $field
120
     * @param string $query
121
     * @param float  $cutoffFrequency percentage in decimal form (.001 == 0.1%)
122
     *
123
     * @return Common
124
     */
125
    public function common_terms($field, $query, $cutoffFrequency)
126
    {
127
        return new Common($field, $query, $cutoffFrequency);
128
    }
129
130
    /**
131
     * constant score query.
132
     *
133
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html
134
     *
135
     * @param null|\Elastica\Query\AbstractQuery|array $filter
136
     *
137
     * @return ConstantScore
138
     */
139
    public function constant_score($filter = null)
140
    {
141
        return new ConstantScore($filter);
0 ignored issues
show
Bug introduced by
It seems like $filter defined by parameter $filter on line 139 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...
142
    }
143
144
    /**
145
     * dis max query.
146
     *
147
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html
148
     *
149
     * @return DisMax
150
     */
151
    public function dis_max()
152
    {
153
        return new DisMax();
154
    }
155
156
    /**
157
     * function score query.
158
     *
159
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html
160
     *
161
     * @return FunctionScore
162
     */
163
    public function function_score()
164
    {
165
        return new FunctionScore();
166
    }
167
168
    /**
169
     * fuzzy query.
170
     *
171
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html
172
     *
173
     * @param string $fieldName Field name
174
     * @param string $value     String to search for
175
     *
176
     * @return Fuzzy
177
     */
178
    public function fuzzy($fieldName = null, $value = null)
179
    {
180
        return new Fuzzy($fieldName, $value);
181
    }
182
183
    /**
184
     * geo shape query.
185
     *
186
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html
187
     */
188
    public function geo_shape()
189
    {
190
        throw new NotImplementedException();
191
    }
192
193
    /**
194
     * has child query.
195
     *
196
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html
197
     *
198
     * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query
199
     * @param string                                               $type  Parent document type
200
     *
201
     * @return HasChild
202
     */
203
    public function has_child($query, $type = null)
204
    {
205
        return new HasChild($query, $type);
206
    }
207
208
    /**
209
     * has parent query.
210
     *
211
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html
212
     *
213
     * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query
214
     * @param string                                               $type  Parent document type
215
     *
216
     * @return HasParent
217
     */
218
    public function has_parent($query, $type)
219
    {
220
        return new HasParent($query, $type);
221
    }
222
223
    /**
224
     * ids query.
225
     *
226
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html
227
     *
228
     * @param array|string|\Elastica\Type $type
229
     * @param array                       $ids
230
     *
231
     * @return Ids
232
     */
233
    public function ids($type = null, array $ids = [])
234
    {
235
        return new Ids($type, $ids);
236
    }
237
238
    /**
239
     * match all query.
240
     *
241
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html
242
     *
243
     * @return MatchAll
244
     */
245
    public function match_all()
246
    {
247
        return new MatchAll();
248
    }
249
250
    /**
251
     * match none query.
252
     *
253
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html#query-dsl-match-none-query
254
     *
255
     * @return MatchNone
256
     */
257
    public function match_none()
258
    {
259
        return new MatchNone();
260
    }
261
262
    /**
263
     * more like this query.
264
     *
265
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html
266
     *
267
     * @return MoreLikeThis
268
     */
269
    public function more_like_this()
270
    {
271
        return new MoreLikeThis();
272
    }
273
274
    /**
275
     * nested query.
276
     *
277
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html
278
     *
279
     * @return Nested
280
     */
281
    public function nested()
282
    {
283
        return new Nested();
284
    }
285
286
    /**
287
     * prefix query.
288
     *
289
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html
290
     *
291
     * @param array $prefix Prefix array
292
     *
293
     * @return Prefix
294
     */
295
    public function prefix(array $prefix = [])
296
    {
297
        return new Prefix($prefix);
298
    }
299
300
    /**
301
     * query string query.
302
     *
303
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
304
     *
305
     * @param string $queryString OPTIONAL Query string for object
306
     *
307
     * @return QueryString
308
     */
309
    public function query_string($queryString = '')
310
    {
311
        return new QueryString($queryString);
312
    }
313
314
    /**
315
     * simple_query_string query.
316
     *
317
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html
318
     *
319
     * @param string $query
320
     * @param array  $fields
321
     *
322
     * @return SimpleQueryString
323
     */
324
    public function simple_query_string($query, array $fields = [])
325
    {
326
        return new SimpleQueryString($query, $fields);
327
    }
328
329
    /**
330
     * range query.
331
     *
332
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
333
     *
334
     * @param string $fieldName
335
     * @param array  $args
336
     *
337
     * @return Range
338
     */
339
    public function range($fieldName = null, array $args = [])
340
    {
341
        return new Range($fieldName, $args);
342
    }
343
344
    /**
345
     * regexp query.
346
     *
347
     * @param string $key
348
     * @param string $value
349
     * @param float  $boost
350
     *
351
     * @return Regexp
352
     *
353
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html
354
     */
355
    public function regexp($key = '', $value = null, $boost = 1.0)
356
    {
357
        return new Regexp($key, $value, $boost);
358
    }
359
360
    /**
361
     * span first query.
362
     *
363
     * @param \Elastica\Query\AbstractQuery|array $match
364
     * @param int                                 $end
365
     *
366
     * @return SpanFirst
367
     *
368
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html
369
     */
370
    public function span_first($match = null, $end = null)
371
    {
372
        return new SpanFirst($match, $end);
373
    }
374
375
    /**
376
     * span multi term query.
377
     *
378
     * @param \Elastica\Query\AbstractQuery|array $match
379
     *
380
     * @return SpanMulti
381
     *
382
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-multi-term-query.html
383
     */
384
    public function span_multi_term($match = null)
385
    {
386
        return new SpanMulti($match);
387
    }
388
389
    /**
390
     * span near query.
391
     *
392
     * @param array $clauses
393
     * @param int   $slop
394
     * @param bool  $inOrder
395
     *
396
     * @return SpanNear
397
     *
398
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html
399
     */
400
    public function span_near($clauses = [], $slop = 1, $inOrder = false)
401
    {
402
        return new SpanNear($clauses, $slop, $inOrder);
403
    }
404
405
    /**
406
     * span not query.
407
     *
408
     * @param AbstractSpanQuery|null $include
409
     * @param AbstractSpanQuery|null $exclude
410
     *
411
     * @return SpanNot
412
     *
413
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-not-query.html
414
     */
415
    public function span_not(AbstractSpanQuery $include = null, AbstractSpanQuery $exclude = null)
416
    {
417
        return new SpanNot($include, $exclude);
418
    }
419
420
    /**
421
     * span_or query.
422
     *
423
     * @param array $clauses
424
     *
425
     * @return SpanOr
426
     *
427
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-or-query.html
428
     */
429
    public function span_or($clauses = [])
430
    {
431
        return new SpanOr($clauses);
432
    }
433
434
    /**
435
     * span_term query.
436
     *
437
     * @param array $term
438
     *
439
     * @return SpanTerm
440
     *
441
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-term-query.html
442
     */
443
    public function span_term(array $term = [])
444
    {
445
        return new SpanTerm($term);
446
    }
447
448
    /**
449
     * span_containing query.
450
     *
451
     * @param AbstractSpanQuery|null $little
452
     * @param AbstractSpanQuery|null $big
453
     *
454
     * @return SpanContaining
455
     *
456
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-containing-query.html
457
     */
458
    public function span_containing(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null)
459
    {
460
        return new SpanContaining($little, $big);
461
    }
462
463
    /**
464
     * span_within query.
465
     *
466
     * @param AbstractSpanQuery|null $little
467
     * @param AbstractSpanQuery|null $big
468
     *
469
     * @return SpanWithin
470
     *
471
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-within-query.html
472
     */
473
    public function span_within(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null)
474
    {
475
        return new SpanWithin($little, $big);
476
    }
477
478
    /**
479
     * term query.
480
     *
481
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
482
     *
483
     * @param array $term
484
     *
485
     * @return Term
486
     */
487
    public function term(array $term = [])
488
    {
489
        return new Term($term);
490
    }
491
492
    /**
493
     * terms query.
494
     *
495
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
496
     *
497
     * @param string $key
498
     * @param array  $terms
499
     *
500
     * @return Terms
501
     */
502
    public function terms($key = '', array $terms = [])
503
    {
504
        return new Terms($key, $terms);
505
    }
506
507
    /**
508
     * wildcard query.
509
     *
510
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html
511
     *
512
     * @param string $key   OPTIONAL Wildcard key
513
     * @param string $value OPTIONAL Wildcard value
514
     * @param float  $boost OPTIONAL Boost value (default = 1)
515
     *
516
     * @return Wildcard
517
     */
518
    public function wildcard($key = '', $value = null, $boost = 1.0)
519
    {
520
        return new Wildcard($key, $value, $boost);
521
    }
522
523
    /**
524
     * geo distance query.
525
     *
526
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
527
     *
528
     * @param string       $key
529
     * @param array|string $location
530
     * @param string       $distance
531
     *
532
     * @return GeoDistance
533
     */
534
    public function geo_distance($key, $location, $distance)
535
    {
536
        return new GeoDistance($key, $location, $distance);
537
    }
538
539
    /**
540
     * exists query.
541
     *
542
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
543
     *
544
     * @param string $field
545
     *
546
     * @return Exists
547
     */
548
    public function exists($field)
549
    {
550
        return new Exists($field);
551
    }
552
553
    /**
554
     * type query.
555
     *
556
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-type-query.html
557
     *
558
     * @param string $type Type name
559
     *
560
     * @return Type
561
     */
562
    public function type($type = null)
563
    {
564
        return new Type($type);
565
    }
566
567
    /**
568
     * type query.
569
     *
570
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-percolate-query.html
571
     *
572
     * @return Percolate
573
     */
574
    public function percolate()
575
    {
576
        return new Percolate();
577
    }
578
}
579