Skip to content

Commit 27b2115

Browse files
Always upsert on update
1 parent ad28d27 commit 27b2115

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/EventListener/TypesenseIndexer.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ private function indexDocuments()
125125
private function updateDocuments()
126126
{
127127
foreach ($this->documentsToUpdate as $documentToUpdate) {
128-
$this->documentManager->delete($documentToUpdate[0], $documentToUpdate[1]);
129-
$this->documentManager->index($documentToUpdate[0], $documentToUpdate[2]);
128+
$this->documentManager->upsert($documentToUpdate[0], $documentToUpdate[1]);
130129
}
131130
}
132131

src/Manager/DocumentManager.php

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ public function index($collection, $data)
3333
return $this->client->collections[$collection]->documents->create($data);
3434
}
3535

36+
public function upsert($collection, $data)
37+
{
38+
if (!$this->client->isOperationnal()) {
39+
return null;
40+
}
41+
42+
return $this->client->collections[$collection]->documents->upsert($data);
43+
}
44+
3645
public function import(string $collection, array $data, string $action = 'create')
3746
{
3847
if (!$this->client->isOperationnal() || empty($data)) {

0 commit comments

Comments
 (0)