Skip to content

Commit cf1c1de

Browse files
authored
Merge pull request #17 from typesense/15-review-fixes
Fix soft delete check, null check
2 parents acb1bcd + 02227e0 commit cf1c1de

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

src/Engines/TypesenseEngine.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
use Illuminate\Support\Str;
1212
use Laravel\Scout\Builder;
1313
use Laravel\Scout\Engines\Engine;
14+
use Illuminate\Support\Facades\Config;
1415

1516
/**
16-
* Class TypesenseSearchEngine.
17+
* Class TypesenseEngine.
1718
*
1819
* @date 4/5/20
1920
*
@@ -22,7 +23,7 @@
2223
class TypesenseEngine extends Engine
2324
{
2425
/**
25-
* @var \Typesense\LaravelTypesense\Typesense
26+
* @var Typesense
2627
*/
2728
private Typesense $typesense;
2829

@@ -57,9 +58,9 @@ class TypesenseEngine extends Engine
5758
private array $locationOrderBy = [];
5859

5960
/**
60-
* TypesenseSearchEngine constructor.
61+
* TypesenseEngine constructor.
6162
*
62-
* @param \Typesense\LaravelTypesense\Typesense $typesense
63+
* @param Typesense $typesense
6364
*/
6465
public function __construct(Typesense $typesense)
6566
{
@@ -78,7 +79,7 @@ public function update($models): void
7879
{
7980
$collection = $this->typesense->getCollectionIndex($models->first());
8081

81-
if ($this->usesSoftDelete($models->first()) && $models->first()->softDelete) {
82+
if ($this->usesSoftDelete($models->first()) && config('scout.soft_delete', false)) {
8283
$models->each->pushSoftDeleteMetadata();
8384
}
8485

src/Typesense.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ public function upsertDocument(Collection $collectionIndex, $array): TypesenseDo
9494
/**
9595
* @var $document Document
9696
*/
97-
$document = $collectionIndex->getDocuments()[$array['id']] ?? null;
98-
if ($document === null) {
99-
throw new ObjectNotFound();
100-
}
97+
$document = $collectionIndex->getDocuments()[$array['id']];
10198

10299
try {
103100
$document->retrieve();
@@ -126,10 +123,7 @@ public function deleteDocument(Collection $collectionIndex, $modelId): array
126123
/**
127124
* @var $document Document
128125
*/
129-
$document = $collectionIndex->getDocuments()[(string) $modelId] ?? null;
130-
if ($document === null) {
131-
throw new ObjectNotFound();
132-
}
126+
$document = $collectionIndex->getDocuments()[(string) $modelId];
133127

134128
return $document->delete();
135129
}
@@ -188,11 +182,7 @@ public function importDocuments(Collection $collectionIndex, $documents, string
188182
*/
189183
public function deleteCollection(string $collectionName): array
190184
{
191-
$index = $this->client->getCollections()->{$collectionName} ?? null;
192-
if ($index === null) {
193-
throw new ObjectNotFound();
194-
}
195-
185+
$index = $this->client->getCollections()->{$collectionName};
196186
return $index->delete();
197187
}
198188
}

0 commit comments

Comments
 (0)