diff --git a/src/DSL/SearchBuilder.php b/src/DSL/SearchBuilder.php index 362e67f..55383b2 100644 --- a/src/DSL/SearchBuilder.php +++ b/src/DSL/SearchBuilder.php @@ -683,6 +683,22 @@ public function nested($field, \Closure $closure, $score_mode = 'avg') return $this; } + /** + * Set a search_after query. + * + * @param $value + * + * @return $this + */ + public function searchAfter($value) + { + $values = is_array($value) ? $value : func_get_args(); + $this->query->setFrom(-1); + $this->query->setSearchAfter($values); + + return $this; + } + /** * Add aggregation. * diff --git a/src/Fillers/EloquentFiller.php b/src/Fillers/EloquentFiller.php index 714ace2..296f61f 100644 --- a/src/Fillers/EloquentFiller.php +++ b/src/Fillers/EloquentFiller.php @@ -72,6 +72,11 @@ public function fillModel(Model $model, $hit = []) $instance->highlight = $hit['highlight']; } + //set sort for search_after query + if (isset($hit['sort'])) { + $instance->sort = $hit['sort']; + } + return $instance; } diff --git a/tests/DSL/SearchBuilderTest.php b/tests/DSL/SearchBuilderTest.php index a2dda60..8dc0c58 100644 --- a/tests/DSL/SearchBuilderTest.php +++ b/tests/DSL/SearchBuilderTest.php @@ -529,6 +529,19 @@ public function it_set_a_field_function_score() ], $builder->toDSL()); } + /** + * @test + */ + public function it_set_a_search_after_query() + { + $builder = $this->getBuilder(); + + $time = time(); + $builder->searchAfter($time); + + $this->assertEquals(['from' => -1, 'search_after' => [$time]], $builder->toDSL()); + } + /** * @test */