TypesenseBundle icon indicating copy to clipboard operation
TypesenseBundle copied to clipboard

Hotfix: load the client if collection array is empty and allow to use everything dynamically

Open EfrosIonelu opened this issue 1 year ago • 2 comments

  • load the client if collection array is empty and allow to use everything dynamically

EfrosIonelu avatar Jan 17 '25 05:01 EfrosIonelu

Hello @EfrosIonelu by curiosity, why would you need to load the config if no collections are defined ?

npotier avatar Feb 18 '25 09:02 npotier

Hi, sure, there is my example: I added current library but i do not have any entity to typesense collection representation, Instead i need to migrate to typesense dynamic collections that do not have model representation,

The idea is to have access to TypesenseClient, if there are not collection and add collection definition dynamically

...
public function __construct(
    private readonly TypesenseClient  $typesenseClient,
...
if ($this->typesenseClient->getCollections()['example']->exists()) {
    $this->typesenseClient->getCollections()['example']->delete();
}
....
$this->typesenseClient->getCollections()->create([
            'name' => 'example',
            'enable_nested_fields' => true,
            'fields' => [
                ....
             ]       
....
$this->typesenseClient->getCollections()['example']->documents->upsert($data);
....

EfrosIonelu avatar Feb 18 '25 11:02 EfrosIonelu