Skip to content

Commit b5b6d5a

Browse files
authored
fix(typesense): handle missing collection during search (#914) (#917)
* fix(typesense): handle missing collection during search - wrap `search` operation in try-catch block to handle `ObjectNotFound` exception - automatically create collection when not found and retry search - improve error recovery flow for typesense engine * chore: lint
1 parent e53ebde commit b5b6d5a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Engines/TypesenseEngine.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Typesense\Client as Typesense;
1414
use Typesense\Collection as TypesenseCollection;
1515
use Typesense\Exceptions\ObjectAlreadyExists;
16+
use Typesense\Exceptions\ObjectNotFound;
1617
use Typesense\Exceptions\TypesenseClientError;
1718

1819
class TypesenseEngine extends Engine
@@ -255,7 +256,13 @@ protected function performSearch(Builder $builder, array $options = []): mixed
255256
return call_user_func($builder->callback, $documents, $builder->query, $options);
256257
}
257258

258-
return $documents->search($options);
259+
try {
260+
return $documents->search($options);
261+
} catch (ObjectNotFound) {
262+
$this->getOrCreateCollectionFromModel($builder->model, $builder->index, true);
263+
264+
return $documents->search($options);
265+
}
259266
}
260267

261268
/**

0 commit comments

Comments
 (0)