Skip to content

Commit c961428

Browse files
committed
Options can have scroll and scroll_id
- ResultMapper some undefined array fixes
1 parent 9c0eab7 commit c961428

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

src/Options.php

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,33 @@ class Options
2626
* @var bool
2727
*/
2828
private $includeVersion;
29+
/**
30+
* @var string|null
31+
*/
32+
private $scroll;
33+
/**
34+
* @var string|null
35+
*/
36+
private $scrollId;
2937

3038

3139
public function __construct(
3240
?int $size = NULL,
3341
?int $from = NULL,
3442
?\Spameri\ElasticQuery\Options\SortCollection $sort = NULL,
3543
?float $minScore = NULL,
36-
bool $includeVersion = FALSE
44+
bool $includeVersion = FALSE,
45+
?string $scroll = NULL,
46+
?string $scrollId = NULL
3747
)
3848
{
3949
$this->size = $size;
4050
$this->from = $from;
4151
$this->sort = $sort ?: new \Spameri\ElasticQuery\Options\SortCollection();
4252
$this->minScore = $minScore;
4353
$this->includeVersion = $includeVersion;
54+
$this->scroll = $scroll;
55+
$this->scrollId = $scrollId;
4456
}
4557

4658

@@ -56,6 +68,40 @@ public function changeSize(int $size) : void
5668
}
5769

5870

71+
public function sort() : \Spameri\ElasticQuery\Options\SortCollection
72+
{
73+
return $this->sort;
74+
}
75+
76+
77+
public function scroll() : ?string
78+
{
79+
return $this->scroll;
80+
}
81+
82+
83+
public function startScroll(
84+
string $scroll
85+
) : void
86+
{
87+
$this->scroll = $scroll;
88+
}
89+
90+
91+
public function scrollId() : ?string
92+
{
93+
return $this->scrollId;
94+
}
95+
96+
97+
public function scrollInitialized(
98+
string $scrollId
99+
) : void
100+
{
101+
$this->scrollId = $scrollId;
102+
}
103+
104+
59105
public function toArray() : array
60106
{
61107
$array = [];
@@ -80,13 +126,12 @@ public function toArray() : array
80126
$array['version'] = $this->includeVersion;
81127
}
82128

83-
return $array;
84-
}
85-
129+
if ($this->scrollId !== NULL) {
130+
$array['scroll_id'] = $this->scrollId;
131+
$array['scroll'] = $this->scroll;
132+
}
86133

87-
public function sort() : \Spameri\ElasticQuery\Options\SortCollection
88-
{
89-
return $this->sort;
134+
return $array;
90135
}
91136

92137
}

src/Response/ResultMapper.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,11 @@ public function mapAggregations(
135135
{
136136
$aggregationArray = [];
137137
$i = 0;
138-
foreach ($elasticSearchResponse['aggregations'] as $aggregationName => $aggregation) {
139-
$aggregationArray[] = $this->mapAggregation($aggregationName, $i, $aggregation);
140-
$i++;
138+
if (isset($elasticSearchResponse['aggregations'])) {
139+
foreach ($elasticSearchResponse['aggregations'] as $aggregationName => $aggregation) {
140+
$aggregationArray[] = $this->mapAggregation($aggregationName, $i, $aggregation);
141+
$i++;
142+
}
141143
}
142144

143145
return new \Spameri\ElasticQuery\Response\Result\AggregationCollection(
@@ -222,7 +224,7 @@ public function mapShards(
222224
return new Shards(
223225
$elasticSearchResponse['_shards']['total'],
224226
$elasticSearchResponse['_shards']['successful'],
225-
$elasticSearchResponse['_shards']['skipped'],
227+
$elasticSearchResponse['_shards']['skipped'] ?? 0,
226228
$elasticSearchResponse['_shards']['failed']
227229
);
228230
}

0 commit comments

Comments
 (0)