Skip to content

Commit 32dbefe

Browse files
authored
Merge pull request #14 from guram-vashakidze/main
Add ability to use search_after parameter
2 parents b5e3070 + d78b641 commit 32dbefe

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

src/DSL/Bridge.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,10 @@ private function _sanitizeSearchResponse($response, $params, $queryTag)
10591059
$datum['_meta']['highlights'] = $this->_sanitizeHighlights($hit['highlight']);
10601060
}
10611061

1062+
if (!empty($hit['sort']) && is_array($hit['sort'])) {
1063+
$datum['_meta']['sort'] = $hit['sort'];
1064+
}
1065+
10621066
$datum['_meta']['_index'] = $hit['_index'];
10631067
$datum['_meta']['_id'] = $hit['_id'];
10641068
if (!empty($hit['_score'])) {

src/DSL/QueryBuilder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ private function _buildOptions($options): array
440440
}
441441
}
442442
break;
443+
case 'search_after':
444+
$return['body']['search_after'] = $value;
445+
break;
443446
case 'skip':
444447
$return['from'] = $value;
445448
break;

src/Eloquent/Builder.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,15 @@ public function minScore(float $value)
441441
return $this;
442442
}
443443

444+
public function searchAfter(array $sort): self
445+
{
446+
if (empty($sort)) {
447+
return $this;
448+
}
449+
$this->query->searchAfter($sort);
450+
return $this;
451+
}
452+
444453
/**
445454
* @param string $field
446455
* @param int|null $boostFactor

src/Eloquent/Docs/ModelDocs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* @method $this minScore(float $value)
2020
* @method $this field(string $field, int $boostFactor = null)
2121
* @method $this fields(array $fields)
22+
* @method $this searchAfter(array $sort)
2223
* @method sum(array|string $columns)
2324
* @method min(array|string $columns)
2425
* @method max(array|string $columns)

src/Query/Builder.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Builder extends BaseBuilder
3636

3737
public $filters = [];
3838

39+
public $searchAfter = [];
40+
3941
/**
4042
* Clause ops.
4143
*
@@ -792,6 +794,15 @@ public function orWhereRegex($column, $expression)
792794
return $this;
793795
}
794796

797+
public function searchAfter($sort)
798+
{
799+
if (!is_array($sort) || !Arr::isList($sort)) {
800+
throw new RuntimeException('Incorrect "searchAfter" value');
801+
}
802+
$this->searchAfter = $sort;
803+
return $this;
804+
}
805+
795806
/**
796807
* @inheritdoc
797808
*/
@@ -857,6 +868,9 @@ protected function compileOptions()
857868
if ($this->filters) {
858869
$options['filters'] = $this->filters;
859870
}
871+
if (!empty($this->searchAfter)) {
872+
$options['search_after'] = $this->searchAfter;
873+
}
860874

861875
return $options;
862876
}

0 commit comments

Comments
 (0)