-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOptions.php
More file actions
111 lines (79 loc) · 1.77 KB
/
Options.php
File metadata and controls
111 lines (79 loc) · 1.77 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
<?php
declare(strict_types = 1);
namespace Spameri\ElasticQuery;
class Options
{
private \Spameri\ElasticQuery\Options\SortCollection $sort;
public function __construct(
private int|null $size = null,
private int|null $from = null,
\Spameri\ElasticQuery\Options\SortCollection|null $sort = null,
private float|null $minScore = null,
private bool $includeVersion = false,
private string|null $scroll = null,
private string|null $scrollId = null,
)
{
$this->sort = $sort ?: new \Spameri\ElasticQuery\Options\SortCollection();
}
public function changeFrom(int $from): void
{
$this->from = $from;
}
public function changeSize(int $size): void
{
$this->size = $size;
}
public function sort(): \Spameri\ElasticQuery\Options\SortCollection
{
return $this->sort;
}
public function scroll(): string|null
{
return $this->scroll;
}
public function startScroll(
string $scroll,
): void
{
$this->scroll = $scroll;
}
public function scrollId(): string|null
{
return $this->scrollId;
}
public function scrollInitialized(
string $scrollId,
): void
{
$this->scrollId = $scrollId;
}
public function toArray(): array
{
$array = [];
if ($this->from !== null) {
$array['from'] = $this->from;
}
if ($this->size !== null) {
$array['size'] = $this->size;
}
foreach ($this->sort as $item) {
if ($item->field === '_score') {
$array['sort'][] = $item->field;
continue;
}
$array['sort'][] = $item->toArray();
}
if ($this->minScore) {
$array['min_score'] = $this->minScore;
}
if ($this->includeVersion === true) {
$array['version'] = $this->includeVersion;
}
if ($this->scrollId !== null) {
$array['scroll_id'] = $this->scrollId;
$array['scroll'] = $this->scroll;
}
return $array;
}
}