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

TermQuery::setBoost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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