|
1 | 1 | # Laravel Typesense Tools |
2 | 2 |
|
3 | | -`synergitech/laravel-typesense-tools` adds Artisan commands that help manage Typesense collections and aliases in Laravel applications using Scout. |
4 | | - |
5 | | -## What this package provides |
6 | | - |
7 | | -- `search:setup` to ensure collections exist and (optionally) import data. |
8 | | -- `search:switch-alias` to point aliases at the current index collections. |
9 | | -- `search:delete-index {suffix}` to remove old suffixed collections. |
10 | | -- `search:cleanup` to remove collections that are not referenced by an alias. |
| 3 | +This package adds Artisan commands that help manage Typesense collections and aliases in Laravel applications using Scout. |
11 | 4 |
|
12 | 5 | ## Requirements |
13 | 6 |
|
|
22 | 15 | composer require synergitech/laravel-typesense-tools |
23 | 16 | ``` |
24 | 17 |
|
| 18 | +## What this package provides |
| 19 | + |
| 20 | +- `search:setup` to ensure collections exist and (optionally) import data. |
| 21 | +- `search:switch-alias` to point aliases at the current index collections. |
| 22 | +- `search:delete-index {suffix}` to remove old suffixed collections. |
| 23 | +- `search:cleanup` to remove collections that are not referenced by an alias. |
| 24 | + |
25 | 25 | ## Configuration expectations |
26 | 26 |
|
27 | 27 | This package reads model configuration from: |
28 | 28 |
|
29 | 29 | - `config('scout.typesense.model-settings')` |
30 | 30 |
|
31 | | -For each configured model, this package expects: |
| 31 | +For each configured model, define settings like: |
32 | 32 |
|
33 | | -- `indexableAs()` (used for collection names) |
34 | | -- `searchableAs()` (used for alias names and deletion targets) |
| 33 | +- `name` (typically `Model::indexableAs()`) |
| 34 | +- `collection-schema` (Typically `User::getCollectionSchema()`) |
| 35 | +- `search-parameters.query_by` (comma-separated searchable fields) |
35 | 36 |
|
36 | | -When creating missing collections, `search:setup` uses the model schema from: |
37 | | - |
38 | | -- `scout.typesense.model-settings.<ModelClass>.collection-schema` |
| 37 | +See the full examples in [`examples/models/User.php`](examples/models/User.php) and [`examples/config/scout.php`](examples/config/scout.php). |
39 | 38 |
|
40 | 39 | Example `config/scout.php` shape: |
41 | 40 |
|
42 | 41 | ```php |
| 42 | +use App\Models\User; |
| 43 | + |
43 | 44 | 'typesense' => [ |
44 | 45 | 'model-settings' => [ |
45 | | - App\\Models\\Post::class => [ |
46 | | - 'collection-schema' => [ |
47 | | - 'name' => 'posts_tmp_20260325', |
48 | | - 'fields' => [ |
49 | | - ['name' => 'id', 'type' => 'string'], |
50 | | - ['name' => 'title', 'type' => 'string'], |
51 | | - ], |
| 46 | + User::class => [ |
| 47 | + 'name' => User::indexableAs(), |
| 48 | + 'collection-schema' => User::getCollectionSchema(), |
| 49 | + 'search-parameters' => [ |
| 50 | + 'query_by' => implode(',', User::typesenseQueryBy()), |
52 | 51 | ], |
53 | 52 | ], |
54 | 53 | ], |
|
0 commit comments