Skip to content

Commit

Permalink
Merge pull request #17 from typesense/15-review-fixes
Browse files Browse the repository at this point in the history
Fix soft delete check, null check
  • Loading branch information
hi019 committed Dec 3, 2021
2 parents acb1bcd + 02227e0 commit cf1c1de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
11 changes: 6 additions & 5 deletions src/Engines/TypesenseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
use Illuminate\Support\Str;
use Laravel\Scout\Builder;
use Laravel\Scout\Engines\Engine;
use Illuminate\Support\Facades\Config;

/**
* Class TypesenseSearchEngine.
* Class TypesenseEngine.
*
* @date 4/5/20
*
Expand All @@ -22,7 +23,7 @@
class TypesenseEngine extends Engine
{
/**
* @var \Typesense\LaravelTypesense\Typesense
* @var Typesense
*/
private Typesense $typesense;

Expand Down Expand Up @@ -57,9 +58,9 @@ class TypesenseEngine extends Engine
private array $locationOrderBy = [];

/**
* TypesenseSearchEngine constructor.
* TypesenseEngine constructor.
*
* @param \Typesense\LaravelTypesense\Typesense $typesense
* @param Typesense $typesense
*/
public function __construct(Typesense $typesense)
{
Expand All @@ -78,7 +79,7 @@ public function update($models): void
{
$collection = $this->typesense->getCollectionIndex($models->first());

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

Expand Down
16 changes: 3 additions & 13 deletions src/Typesense.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ public function upsertDocument(Collection $collectionIndex, $array): TypesenseDo
/**
* @var $document Document
*/
$document = $collectionIndex->getDocuments()[$array['id']] ?? null;
if ($document === null) {
throw new ObjectNotFound();
}
$document = $collectionIndex->getDocuments()[$array['id']];

try {
$document->retrieve();
Expand Down Expand Up @@ -126,10 +123,7 @@ public function deleteDocument(Collection $collectionIndex, $modelId): array
/**
* @var $document Document
*/
$document = $collectionIndex->getDocuments()[(string) $modelId] ?? null;
if ($document === null) {
throw new ObjectNotFound();
}
$document = $collectionIndex->getDocuments()[(string) $modelId];

return $document->delete();
}
Expand Down Expand Up @@ -188,11 +182,7 @@ public function importDocuments(Collection $collectionIndex, $documents, string
*/
public function deleteCollection(string $collectionName): array
{
$index = $this->client->getCollections()->{$collectionName} ?? null;
if ($index === null) {
throw new ObjectNotFound();
}

$index = $this->client->getCollections()->{$collectionName};
return $index->delete();
}
}

0 comments on commit cf1c1de

Please sign in to comment.