Skip to content
This repository has been archived by the owner on May 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #20 from alifjafar/master
Browse files Browse the repository at this point in the history
fix pagination
  • Loading branch information
shokme authored May 7, 2020
2 parents e801e0e + c14a9c8 commit ae318c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Engines/MeilisearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function paginate(Builder $builder, $perPage, $page)
return $this->performSearch($builder, array_filter([
'filters' => $this->filters($builder),
'limit' => $perPage,
'offset' => ($page - 1) * $perPage,
]));
}

Expand Down
23 changes: 23 additions & 0 deletions tests/MeilisearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,29 @@ public function update_empty_searchable_array_does_not_add_objects_to_index()
$engine = new MeilisearchEngine($client);
$engine->update(Collection::make([new EmptySearchableModel]));
}

/** @test */
public function pagination_correct_parameters()
{
$perPage = 5;
$page = 2;

$client = m::mock(Client::class);
$client->shouldReceive('getIndex')->with('table')->andReturn($index = m::mock(stdClass::class));
$index->shouldReceive('search')->with('mustang', [
'filters' => 'foo=1',
'limit' => $perPage,
'offset' => ($page - 1) * $perPage,
]);

$engine = new MeilisearchEngine($client);
$builder = new Builder(new SearchableModel, 'mustang', function ($meilisearch, $query, $options) {
$options['filters'] = 'foo=1';

return $meilisearch->search($query, $options);
});
$engine->paginate($builder, $perPage, $page);
}
}

class CustomKeySearchableModel extends SearchableModel
Expand Down

0 comments on commit ae318c4

Please sign in to comment.