Completed
Push — develop ( 5325d9...9f3a91 )
by Sam
11s
created

WildcardQuery::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Nord\Lumen\Elasticsearch\Search\Query\TermLevel;
4
5
use Nord\Lumen\Elasticsearch\Exceptions\InvalidArgument;
6
use Nord\Lumen\Elasticsearch\Search\Query\Traits\HasBoost;
7
use Nord\Lumen\Elasticsearch\Search\Query\Traits\HasValue;
8
9
/**
10
 * Class WildcardQuery
11
 * @package Nord\Lumen\Elasticsearch\Search\Query\TermLevel
12
 *
13
 * @see     https://www.elastic.co/guide/en/elasticsearch/reference/2.4/query-dsl-wildcard-query.html
14
 */
15
class WildcardQuery extends AbstractQuery
16
{
17
    use HasBoost;
18
    use HasValue;
19
20
    /**
21
     * @inheritdoc
22
     *
23
     * @throws InvalidArgument
24
     */
25
    public function toArray()
26
    {
27
        if (!isset($this->field) || !isset($this->value)) {
28
            throw new InvalidArgument('"field" and "value" must be set for this type of query');
29
        }
30
31
        $definition = [
32
            'value' => $this->getValue(),
33
        ];
34
35
        if ($this->hasBoost()) {
36
            $definition['boost'] = $this->getBoost();
37
        }
38
39
        return [
40
            'wildcard' => [
41
                $this->getField() => $definition,
42
            ],
43
        ];
44
    }
45
}
46