diff --git a/src/Engines/MeilisearchEngine.php b/src/Engines/MeilisearchEngine.php index a3bb9f0..4bdd160 100644 --- a/src/Engines/MeilisearchEngine.php +++ b/src/Engines/MeilisearchEngine.php @@ -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(); diff --git a/tests/MeilisearchEngineTest.php b/tests/MeilisearchEngineTest.php index 95086f6..226b428 100644 --- a/tests/MeilisearchEngineTest.php +++ b/tests/MeilisearchEngineTest.php @@ -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, @@ -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); @@ -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);