RangeQuery::setLessThanOrEquals()   A
last analyzed

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