Skip to content

Commit 45112cb

Browse files
committed
add scroll feature
1 parent b3c50d6 commit 45112cb

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

src/ElasticEngine.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,43 @@ public function searchRaw(Model $model, $query)
279279
return ElasticClient::search($payload);
280280
}
281281

282+
/**
283+
* Make a raw search with scroll.
284+
*
285+
* @param \Illuminate\Database\Eloquent\Model $model
286+
* @param $query
287+
* @param $size
288+
* @param $scroll
289+
* @return mixed
290+
* @throws \Exception
291+
*/
292+
public function searchRawWithScroll(Model $model, $query, $size = 10000, string $scroll = '10s')
293+
{
294+
$payload = (new TypePayload($model))
295+
->setIfNotEmpty('body', $query)
296+
->set('scroll', $scroll)
297+
->set('size', $size)
298+
->set('sort', ['_doc'])
299+
->get();
300+
301+
return ElasticClient::search($payload);
302+
}
303+
304+
/**
305+
* Make a scroll.
306+
*
307+
* @param $scroll_id
308+
* @param $scroll
309+
* @return mixed
310+
*/
311+
public function scroll(string $scroll_id, string $scroll = '10s')
312+
{
313+
return ElasticClient::scroll([
314+
'scroll' => $scroll,
315+
'scroll_id' => $scroll_id,
316+
]);
317+
}
318+
282319
/**
283320
* {@inheritdoc}
284321
*/

src/Searchable.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,37 @@ public static function searchRaw(array $query)
137137
->searchRaw($model, $query);
138138
}
139139

140+
/**
141+
* Execute a raw search with scroll.
142+
*
143+
* @param $query
144+
* @param $size
145+
* @param $scroll
146+
* @return array
147+
*/
148+
public static function searchRawWithScroll(array $query, int $size = 10000, string $scroll = '10s')
149+
{
150+
$model = new static();
151+
152+
return $model->searchableUsing()
153+
->searchRawWithScroll($model, $query, $size, $scroll);
154+
}
155+
156+
/**
157+
* Execute a scroll search.
158+
*
159+
* @param $scroll_id
160+
* @param $scroll
161+
* @return array
162+
*/
163+
public static function scroll(string $scroll_id, string $scroll = '10s')
164+
{
165+
$model = new static();
166+
167+
return $model->searchableUsing()
168+
->scroll($scroll_id, $scroll);
169+
}
170+
140171
/**
141172
* Set the highlight attribute.
142173
*

0 commit comments

Comments
 (0)