From 9a33fa7923db63ecead9a7b71d0f15749be0f83d Mon Sep 17 00:00:00 2001 From: lubosdz Date: Sun, 27 Oct 2024 11:35:25 +0100 Subject: [PATCH] Fix #352: Add support for query parameter `search_after` to paginate over large datasets --- CHANGELOG.md | 1 + src/Query.php | 6 ++++++ src/QueryBuilder.php | 3 +++ 3 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a15636a..e67629c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Yii Framework 2 Elasticsearch extension Change Log - Bug #344: Disabled JSON pretty print for ElasticSearch bulk API (rhertogh) - Bug #350: Remove deprecated code, set $pagination->totalCount (lav45) +- Bug #352: Add support for query parameter `search_after` to paginate over large datasets (lubosdz) 2.1.4 May 22, 2023 diff --git a/src/Query.php b/src/Query.php index 03e14f92..8ab8e0e2 100644 --- a/src/Query.php +++ b/src/Query.php @@ -236,6 +236,12 @@ class Query extends Component implements QueryInterface * @since 2.0.5 */ public $explain; + /** + * @var array Allows pagination of large datasets. + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after + * @since 2.1.5 + */ + public $search_after = []; /** diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index c1dbcc57..44ac17cf 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -109,6 +109,9 @@ public function build($query) if (!empty($query->collapse)) { $parts['collapse'] = $query->collapse; } + if ($query->search_after) { + $parts['search_after'] = $query->search_after; + } $sort = $this->buildOrderBy($query->orderBy); if (!empty($sort)) {