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

Commit

Permalink
get index or create it with the model primary key if not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
shokme committed Sep 2, 2020
1 parent 0ec2fff commit e1a008a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Engines/MeilisearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function update($models)
return;
}

$index = $this->meilisearch->getIndex($models->first()->searchableAs());
$index = $this->meilisearch->getOrCreateIndex($models->first()->searchableAs(), ['primaryKey' => $models->first()->getKeyName()]);

if ($this->usesSoftDelete($models->first()) && $this->softDelete) {
$models->each->pushSoftDeleteMetadata();
Expand Down
6 changes: 3 additions & 3 deletions tests/MeilisearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function tearDown(): void
public function update_adds_objects_to_index()
{
$client = m::mock(Client::class);
$client->shouldReceive('getIndex')->with('table')->andReturn($index = m::mock(Indexes::class));
$client->shouldReceive('getOrCreateIndex')->with('table', ['primaryKey' => 'id'])->andReturn($index = m::mock(Indexes::class));
$index->shouldReceive('addDocuments')->with([
[
'id' => 1,
Expand Down Expand Up @@ -134,7 +134,7 @@ public function map_method_respects_order()
public function a_model_is_indexed_with_a_custom_meilisearch_key()
{
$client = m::mock(Client::class);
$client->shouldReceive('getIndex')->with('table')->andReturn($index = m::mock(Indexes::class));
$client->shouldReceive('getOrCreateIndex')->with('table', ['primaryKey' => 'id'])->andReturn($index = m::mock(Indexes::class));
$index->shouldReceive('addDocuments')->with([['id' => 'my-meilisearch-key.1']]);

$engine = new MeilisearchEngine($client);
Expand All @@ -156,7 +156,7 @@ public function flush_a_model_with_a_custom_meilisearch_key()
public function update_empty_searchable_array_does_not_add_objects_to_index()
{
$client = m::mock(Client::class);
$client->shouldReceive('getIndex')->with('table')->andReturn($index = m::mock(Indexes::class));
$client->shouldReceive('getOrCreateIndex')->with('table', ['primaryKey' => 'id'])->andReturn($index = m::mock(Indexes::class));
$index->shouldNotReceive('addObjects');

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

0 comments on commit e1a008a

Please sign in to comment.