Skip to content

Commit

Permalink
Always upsert on update
Browse files Browse the repository at this point in the history
  • Loading branch information
developerEinpix committed Apr 21, 2023
1 parent ad28d27 commit 27b2115
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/EventListener/TypesenseIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ private function indexDocuments()
private function updateDocuments()
{
foreach ($this->documentsToUpdate as $documentToUpdate) {
$this->documentManager->delete($documentToUpdate[0], $documentToUpdate[1]);
$this->documentManager->index($documentToUpdate[0], $documentToUpdate[2]);
$this->documentManager->upsert($documentToUpdate[0], $documentToUpdate[1]);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/Manager/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ public function index($collection, $data)
return $this->client->collections[$collection]->documents->create($data);
}

public function upsert($collection, $data)
{
if (!$this->client->isOperationnal()) {
return null;
}

return $this->client->collections[$collection]->documents->upsert($data);
}

public function import(string $collection, array $data, string $action = 'create')
{
if (!$this->client->isOperationnal() || empty($data)) {
Expand Down

0 comments on commit 27b2115

Please sign in to comment.