Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/DSL/SearchBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
5 changes: 5 additions & 0 deletions src/Fillers/EloquentFiller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/DSL/SearchBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down