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

Commit

Permalink
Merge #70
Browse files Browse the repository at this point in the history
70: upgrade for meilisearch-php v0.16 r=curquiza a=shokme

Need meilisearch-php v0.16 to be released, to be able to run tests.

Co-authored-by: Jordan Massart <[email protected]>
Co-authored-by: Clémentine Urquizar <[email protected]>
  • Loading branch information
3 people authored Jan 27, 2021
2 parents 74a5d02 + 4495035 commit 9809ad0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"require": {
"php": "^7.2|^8.0",
"laravel/scout": "^8.0",
"meilisearch/meilisearch-php": "^0.15",
"meilisearch/meilisearch-php": "^0.16",
"http-interop/http-factory-guzzle": "^1.0"
},
"require-dev": {
Expand Down
16 changes: 9 additions & 7 deletions src/Engines/MeilisearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public function __construct(Meilisearch $meilisearch, bool $softDelete = false)
* @param \Illuminate\Database\Eloquent\Collection $models
*
* @return void
*
* @throws \MeiliSearch\Exceptions\HTTPRequestException
*/
public function update($models)
{
Expand Down Expand Up @@ -69,7 +71,7 @@ public function update($models)
*/
public function delete($models)
{
$index = $this->meilisearch->getIndex($models->first()->searchableAs());
$index = $this->meilisearch->index($models->first()->searchableAs());

$index->deleteDocuments(
$models->map->getScoutKey()
Expand Down Expand Up @@ -113,26 +115,26 @@ public function paginate(Builder $builder, $perPage, $page)
*
* @return mixed
*/
protected function performSearch(Builder $builder, array $options = [])
protected function performSearch(Builder $builder, array $searchParams = [])
{
$meilisearch = $this->meilisearch->getIndex($builder->index ?: $builder->model->searchableAs());
$meilisearch = $this->meilisearch->index($builder->index ?: $builder->model->searchableAs());

if ($builder->callback) {
return call_user_func(
$builder->callback,
$meilisearch,
$builder->query,
$options
$searchParams
);
}

return $meilisearch->search($builder->query, $options);
return $meilisearch->rawSearch($builder->query, $searchParams);
}

/**
* Get the filter array for the query.
*
* @return array
* @return string
*/
protected function filters(Builder $builder)
{
Expand Down Expand Up @@ -207,7 +209,7 @@ public function getTotalCount($results)
*/
public function flush($model)
{
$index = $this->meilisearch->getIndex($model->searchableAs());
$index = $this->meilisearch->index($model->searchableAs());

$index->deleteAllDocuments();
}
Expand Down
10 changes: 5 additions & 5 deletions tests/MeilisearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function updateAddsObjectsToIndex()
public function deleteRemovesObjectsToIndex()
{
$client = m::mock(Client::class);
$client->shouldReceive('getIndex')->with('table')->andReturn($index = m::mock(Indexes::class));
$client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class));
$index->shouldReceive('deleteDocuments')->with([1]);

$engine = new MeilisearchEngine($client);
Expand All @@ -48,7 +48,7 @@ public function deleteRemovesObjectsToIndex()
public function searchSendsCorrectParametersToMeilisearch()
{
$client = m::mock(Client::class);
$client->shouldReceive('getIndex')->with('table')->andReturn($index = m::mock(Indexes::class));
$client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class));
$index->shouldReceive('search')->with('mustang', [
'filters' => 'foo=1',
]);
Expand Down Expand Up @@ -145,7 +145,7 @@ public function aModelIsIndexedWithACustomMeilisearchKey()
public function flushAModelWithACustomMeilisearchKey()
{
$client = m::mock(Client::class);
$client->shouldReceive('getIndex')->with('table')->andReturn($index = m::mock(Indexes::class));
$client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class));
$index->shouldReceive('deleteAllDocuments');

$engine = new MeilisearchEngine($client);
Expand All @@ -170,7 +170,7 @@ public function paginationCorrectParameters()
$page = 2;

$client = m::mock(Client::class);
$client->shouldReceive('getIndex')->with('table')->andReturn($index = m::mock(Indexes::class));
$client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class));
$index->shouldReceive('search')->with('mustang', [
'filters' => 'foo=1',
'limit' => $perPage,
Expand Down Expand Up @@ -206,7 +206,7 @@ public function toSearchableArray()
public function update_empty_searchable_array_from_soft_deleted_model_does_not_add_objects_to_index()
{
$client = m::mock(Client::class);
$client->shouldReceive('getIndex')->with('table')->andReturn($index = m::mock(Indexes::class));
$client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class));
$index->shouldNotReceive('addDocuments');

$engine = new MeilisearchEngine($client, true);
Expand Down

0 comments on commit 9809ad0

Please sign in to comment.