laravel / scout

Laravel Scout provides a driver based solution to searching your Eloquent models.
https://laravel.com/docs/scout
MIT License
1.54k stars 327 forks source link

Allow Typesense Search Parameter Definition on Models #827

Closed stammbach closed 4 months ago

stammbach commented 4 months ago

Added the optional typesenseSearchParameters Model Definition to allow declaration of Typesense Search Parameters using Models to extend and streamline the already existing typesenseCollectionSchema functionality.

Currently when utilising the existing typesenseCollectionSchema function, you have to mix and match Model based Defintion with Config Usage, which is not ideal.

With the added typesenseSearchParameters you can define everything utilising only Models.

Before After
File: `Model.php` ```php public function typesenseCollectionSchema(): array { return [ 'enable_nested_fields' => true, 'fields' => [ [ 'name' => '.*', 'type' => 'auto', ], ], ]; } ``` with File: `config/scout.php` ```php return [ 'typesense' => [ 'model-settings' => [ Model::class => [ 'search-parameters' => [ 'query_by' => 'name' ] ] ] ] ]; ``` File: `Model.php` ```php public function typesenseCollectionSchema(): array { return [ 'enable_nested_fields' => true, 'fields' => [ [ 'name' => '.*', 'type' => 'auto', ], ], ]; } public function typesenseSearchParameters(): array { return [ 'query_by' => 'name' ]; } ```