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

TermQuery   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
dl 0
loc 47
rs 10

3 Methods

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