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

RangeQuery::setLessThanOrEquals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php namespace Nord\Lumen\Elasticsearch\Search\Query\TermLevel;
2
3
/**
4
 * Matches documents with fields that have terms within a certain range. The type of the Lucene query depends on the
5
 * field type, for string fields, the TermRangeQuery, while for number/date fields, the query is a NumericRangeQuery.
6
 *
7
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
8
 */
9
class RangeQuery extends AbstractQuery
10
{
11
    
12
    use BoostableQuery;
13
14
    /**
15
     * @var mixed Greater-than or equal to.
16
     */
17
    private $greaterThanOrEqual;
18
19
    /**
20
     * @var mixed Greater-than.
21
     */
22
    private $greaterThan;
23
24
    /**
25
     * @var mixed Less-than or equal to.
26
     */
27
    private $lessThanOrEqual;
28
29
    /**
30
     * @var mixed Less-than.
31
     */
32
    private $lessThan;
33
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function toArray()
39
    {
40
        $range = [];
41
42
        $greaterThanOrEquals = $this->getGreaterThanOrEquals();
43
        if (!is_null($greaterThanOrEquals)) {
44
            $range['gte'] = $greaterThanOrEquals;
45
        }
46
        $greaterThan = $this->getGreaterThan();
47
        if (!is_null($greaterThan)) {
48
            $range['gt'] = $greaterThan;
49
        }
50
        $lessThanOrEquals = $this->getLessThanOrEquals();
51
        if (!is_null($lessThanOrEquals)) {
52
            $range['lte'] = $lessThanOrEquals;
53
        }
54
        $lessThan = $this->getLessThan();
55
        if (!is_null($lessThan)) {
56
            $range['lt'] = $lessThan;
57
        }
58
        $boost = $this->getBoost();
59
        if (!is_null($boost)) {
60
            $range['boost'] = $boost;
61
        }
62
63
        return ['range' => [$this->getField() => $range]];
64
    }
65
66
67
    /**
68
     * @param mixed $greaterThanOrEquals
69
     * @return RangeQuery
70
     */
71
    public function setGreaterThanOrEquals($greaterThanOrEquals)
72
    {
73
        $this->greaterThanOrEqual = $greaterThanOrEquals;
74
        return $this;
75
    }
76
77
78
    /**
79
     * @return mixed
80
     */
81
    public function getGreaterThanOrEquals()
82
    {
83
        return $this->greaterThanOrEqual;
84
    }
85
86
87
    /**
88
     * @param mixed $greaterThan
89
     * @return RangeQuery
90
     */
91
    public function setGreaterThan($greaterThan)
92
    {
93
        $this->greaterThan = $greaterThan;
94
        return $this;
95
    }
96
97
98
    /**
99
     * @return mixed
100
     */
101
    public function getGreaterThan()
102
    {
103
        return $this->greaterThan;
104
    }
105
106
107
    /**
108
     * @param mixed $lessThanOrEqual
109
     * @return RangeQuery
110
     */
111
    public function setLessThanOrEquals($lessThanOrEqual)
112
    {
113
        $this->lessThanOrEqual = $lessThanOrEqual;
114
        return $this;
115
    }
116
117
118
    /**
119
     * @return mixed
120
     */
121
    public function getLessThanOrEquals()
122
    {
123
        return $this->lessThanOrEqual;
124
    }
125
126
127
    /**
128
     * @param mixed $lessThan
129
     * @return RangeQuery
130
     */
131
    public function setLessThan($lessThan)
132
    {
133
        $this->lessThan = $lessThan;
134
        return $this;
135
    }
136
137
138
    /**
139
     * @return mixed
140
     */
141
    public function getLessThan()
142
    {
143
        return $this->lessThan;
144
    }
145
}
146