Completed
Push — develop ( 876780...71f4b2 )
by Sam
10s
created

TermsQuery::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 3
eloc 2
nc 2
nop 2
1
<?php namespace Nord\Lumen\Elasticsearch\Search\Query\TermLevel;
2
3
use Nord\Lumen\Elasticsearch\Search\Query\Traits\HasValues;
4
5
/**
6
 * Filters documents that have fields that match any of the provided terms (not analyzed).
7
 *
8
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
9
 */
10
class TermsQuery extends AbstractQuery
11
{
12
    use HasValues;
13
14
    /**
15
     * TermsQuery constructor.
16
     *
17
     * @param null|string $field
18
     * @param array|null  $values
19
     */
20
    public function __construct(?string $field = null, ?array $values = null)
21
    {
22
        if ($field !== null && $values !== null) {
23
            $this->setField($field)->setValues($values);
24
        }
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function toArray()
31
    {
32
        return [
33
            'terms' => [
34
                $this->getField() => $this->getValues(),
35
            ],
36
        ];
37
    }
38
}
39