Completed
Push — develop ( f07ae4...5325d9 )
by Sam
05:38 queued 03:06
created

WildcardQuery::toArray()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 2
nop 0
dl 0
loc 17
rs 9.2
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\TermLevel\Traits\BoostableQuery;
7
8
/**
9
 * Class WildcardQuery
10
 * @package Nord\Lumen\Elasticsearch\Search\Query\TermLevel
11
 *
12
 * @see     https://www.elastic.co/guide/en/elasticsearch/reference/2.4/query-dsl-wildcard-query.html
13
 */
14
class WildcardQuery extends AbstractQuery
15
{
16
    use BoostableQuery;
17
18
    /**
19
     * @var string
20
     */
21
    private $value;
22
23
    /**
24
     * @inheritdoc
25
     *
26
     * @throws InvalidArgument
27
     */
28
    public function toArray()
29
    {
30
        if (!isset($this->field) || !isset($this->value)) {
31
            throw new InvalidArgument('"field" and "value" must be set for this type of query');
32
        }
33
34
        $definition = [
35
            'value' => $this->getValue(),
36
        ];
37
38
        if ($this->hasBoost()) {
39
            $definition['boost'] = $this->getBoost();
40
        }
41
42
        return [
43
            'wildcard' => [
44
                $this->getField() => $definition,
45
            ],
46
        ];
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getValue()
53
    {
54
        return $this->value;
55
    }
56
57
    /**
58
     * @param string $value
59
     *
60
     * @return $this
61
     */
62
    public function setValue($value)
63
    {
64
        $this->value = $value;
65
66
        return $this;
67
    }
68
}
69