Completed
Pull Request — develop (#17)
by Sam
04:04
created

TermQuery::toArray()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 4
nop 0
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
1
<?php namespace Nord\Lumen\Elasticsearch\Search\Query\TermLevel;
2
3
/**
4
 * The term query finds documents that contain the exact term specified in the inverted index.
5
 *
6
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
7
 */
8
class TermQuery extends AbstractQuery
9
{
10
    
11
    use BoostableQuery;
12
13
    /**
14
     * @var mixed
15
     */
16
    private $value;
17
18
19
    /**
20
     * @inheritdoc
21
     */
22
    public function toArray()
23
    {
24
        $term = ['value' => $this->getValue()];
25
26
        $boost = $this->getBoost();
27
        if (!is_null($boost)) {
28
            $term['boost'] = $boost;
29
        }
30
31
        if (count($term) === 1 && isset($term['value'])) {
32
            $term = $term['value'];
33
        }
34
35
        return ['term' => [$this->getField() => $term]];
36
    }
37
38
39
    /**
40
     * @param mixed $value
41
     * @return TermQuery
42
     */
43
    public function setValue($value)
44
    {
45
        $this->value = $value;
46
        return $this;
47
    }
48
49
50
    /**
51
     * @return mixed
52
     */
53
    public function getValue()
54
    {
55
        return $this->value;
56
    }
57
}
58