-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathRangeFacet.php
More file actions
279 lines (234 loc) · 5.54 KB
/
RangeFacet.php
File metadata and controls
279 lines (234 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
declare(strict_types=1);
/*
* This file is part of the Solarium package.
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code.
*/
namespace Solarium\Component\Analytics\Facet;
/**
* Range Facet.
*
* @author wicliff <wicliff.wolda@gmail.com>
*/
class RangeFacet extends AbstractFacet
{
/**
* All gap-based ranges include their lower bound.
*/
public const INCLUDE_LOWER = 'lower';
/**
* All gap-based ranges include their upper bound.
*/
public const INCLUDE_UPPER = 'upper';
/**
* The first and last gap ranges include their edge bounds (lower for the first one,
* upper for the last one) even if the corresponding upper/lower option is not specified.
*/
public const INCLUDE_EDGE = 'edge';
/**
* The before and after ranges will be inclusive of their bounds,
* even if the first or last ranges already include those boundaries.
*/
public const INCLUDE_OUTER = 'outer';
/**
* Includes all options: lower, upper, edge, and outer.
*/
public const INCLUDE_ALL = 'all';
/**
* All records with field values lower then lower bound of the first range.
*/
public const OTHER_BEFORE = 'before';
/**
* All records with field values greater then the upper bound of the last range.
*/
public const OTHER_AFTER = 'after';
/**
* All records with field values between the lower bound
* of the first range and the upper bound of the last range.
*/
public const OTHER_BETWEEN = 'between';
/**
* Include facet buckets for none of the above.
*/
public const OTHER_NONE = 'none';
/**
* Include facet buckets for before, after and between.
*/
public const OTHER_ALL = 'all';
/**
* Array of possible includes.
*/
private const INCLUDES = [
self::INCLUDE_LOWER,
self::INCLUDE_UPPER,
self::INCLUDE_EDGE,
self::INCLUDE_OUTER,
self::INCLUDE_ALL,
];
/**
* Array of possible others.
*/
private const OTHERS = [
self::OTHER_BEFORE,
self::OTHER_AFTER,
self::OTHER_BETWEEN,
self::OTHER_NONE,
self::OTHER_ALL,
];
private string $field;
private int $start;
private int $end;
private array $gap = [];
private bool $hardend = false;
private array $include = [];
private array $others = [];
/**
* {@inheritdoc}
*/
public function getType(): string
{
return AbstractFacet::TYPE_RANGE;
}
/**
* @return string
*/
public function getField(): string
{
return $this->field;
}
/**
* @param string $field
*
* @return self Provides fluent interface
*/
public function setField(string $field): self
{
$this->field = $field;
return $this;
}
/**
* @return int
*/
public function getStart(): int
{
return $this->start;
}
/**
* @param int $start
*
* @return self Provides fluent interface
*/
public function setStart(int $start): self
{
$this->start = $start;
return $this;
}
/**
* @return int
*/
public function getEnd(): int
{
return $this->end;
}
/**
* @param int $end
*
* @return self Provides fluent interface
*/
public function setEnd(int $end): self
{
$this->end = $end;
return $this;
}
/**
* @return array
*/
public function getGap(): array
{
return $this->gap;
}
/**
* @param array $gap
*
* @return self Provides fluent interface
*/
public function setGap(array $gap): self
{
$this->gap = $gap;
return $this;
}
/**
* @return bool
*/
public function isHardend(): bool
{
return $this->hardend;
}
/**
* @param bool $hardend
*
* @return self Provides fluent interface
*/
public function setHardend(bool $hardend): self
{
$this->hardend = $hardend;
return $this;
}
/**
* @return array
*/
public function getInclude(): array
{
return array_values(array_intersect(self::INCLUDES, $this->include));
}
/**
* @param array $include
*
* @return self Provides fluent interface
*/
public function setInclude(array $include): self
{
$this->include = $include;
return $this;
}
/**
* @return array
*/
public function getOthers(): array
{
return array_values(array_intersect(self::OTHERS, $this->others));
}
/**
* @param array $others
*
* @return self Provides fluent interface
*/
public function setOthers(array $others): self
{
$this->others = $others;
return $this;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize(): mixed
{
return array_filter(
[
'type' => $this->getType(),
'field' => $this->field,
'start' => $this->start,
'end' => $this->end,
'gap' => $this->gap,
'hardend' => $this->hardend,
'include' => $this->include,
'others' => $this->others,
],
static function ($var): bool {
return null !== $var && (false === \is_array($var) || 0 !== \count($var));
}
);
}
}