-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOptions.php
More file actions
137 lines (107 loc) · 2.06 KB
/
Options.php
File metadata and controls
137 lines (107 loc) · 2.06 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
<?php declare(strict_types = 1);
namespace Spameri\ElasticQuery;
class Options
{
/**
* @var ?int
*/
private $size;
/**
* @var ?int
*/
private $from;
/**
* @var \Spameri\ElasticQuery\Options\SortCollection
*/
private $sort;
/**
* @var ?float
*/
private $minScore;
/**
* @var bool
*/
private $includeVersion;
/**
* @var string|null
*/
private $scroll;
/**
* @var string|null
*/
private $scrollId;
public function __construct(
?int $size = NULL,
?int $from = NULL,
?\Spameri\ElasticQuery\Options\SortCollection $sort = NULL,
?float $minScore = NULL,
bool $includeVersion = FALSE,
?string $scroll = NULL,
?string $scrollId = NULL
)
{
$this->size = $size;
$this->from = $from;
$this->sort = $sort ?: new \Spameri\ElasticQuery\Options\SortCollection();
$this->minScore = $minScore;
$this->includeVersion = $includeVersion;
$this->scroll = $scroll;
$this->scrollId = $scrollId;
}
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
{
return $this->scroll;
}
public function startScroll(
string $scroll
): void
{
$this->scroll = $scroll;
}
public function scrollId(): ?string
{
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) {
$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;
}
}