Search
Eclipse plugins are already integrated with the global search and Typesense.
Set up Scout and Typesense
In the default Eclipse app, Typesense is already configured as the Laravel Scout driver.
However, in case you need to add Typesense to an existing project, first add the service specification in your Lando file:
services:
typesense:
type: typesense:28.0
portforward: 8108
apiKey: abc
Rebuild the container with lando rebuild -y
.
Secondly, follow the Scout installation instructions here, but do not change your model — this is done later below.
Then, set the same API key in your .env
file and use typesense
as host.
SCOUT_DRIVER=typesense
SCOUT_QUEUE=true
TYPESENSE_API_KEY=abc
TYPESENSE_HOST=typesense
The Typesense service will now be running and ready to use by your app.
Preparing the model for search
- Add the
Eclipse\Common\Foundation\Models\IsSearchable
trait to your model class (e.g.Product
). - Implement the
getTypesenseSettings()
method in your model. For the key-value format, follow the Laravel Scout docs.
See our Product specification here in the catalogue plugin for a working example.
Notes: - Add the model settings to the Scout config.
In your service providerregister
method, inject your model's settings into thescout.typesense.model-settings
config array, e.g.:phppublic function register() { parent::register(); $settings = Config::get('scout.typesense.model-settings', []); $settings += [ Product::class => Product::getTypesenseSettings(), // More models here... ]; Config::set('scout.typesense.model-settings', $settings); }
Enabling search in Filament controllers
- Add the
Eclipse\Common\Foundation\Pages\HasScoutSearch
trait to your FilamentList
controller (e.g.ListProducts
). - Add the
->searchable()
method call to your table definition in your FilamentResource
class (e.g.ProductResource
).phppublic static function table(Table $table): Table { return $table ->columns([ TextColumn::make('id'), TextColumn::make('name') ->toggleable(false), ]) ->searchable(); }
- Implement the
getGloballySearchableAttributes()
method in theResource
class to enable global search for the model, e.g.:phppublic static function getGloballySearchableAttributes(): array { return [ 'code', 'barcode', 'manufacturers_code', 'suppliers_code', 'name', 'short_description', 'description', ]; }
Indexing
Indexing happens on the fly when a model is saved, thanks to the IsSearchable
trait.
However, when initially setting things up for an existing model with records in the database, you need to run the batch import. For our Product
model, you could do that in the console like so:
php artisan scout:import "Eclipse\Catalogue\Product"
Read more about indexing in the Laravel docs here.
Debugging
To better understand and help you debug any problems you may encounter when implementing search with Typesense, you can use the Typesense Dashboard app that is available for all platforms here.
To connect, use the parameters you specified in your Lando file.