Completed
Push — master ( 5140b1...7e846b )
by Nicolas
01:50
created

Query::nested()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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