-
Notifications
You must be signed in to change notification settings - Fork 44
How to setup a custom timeout for a search ? #128
Comments
Hello @desaintflorent, if I'm not wrong this package does not provide an option to set a timeout. I'm not a laravel user so I cannot provide any workaround with laravel. Glad to read you liked the DO tutorial on our docs, we do our best to provide integrations with nice documentation! |
I believe this would have to be done at the Meilisearch PHP Client level by passing a custom GuzzleHTTP instance to the client: https://github.com/meilisearch/meilisearch-php#customize-your-http-client There isn't a way to do this with the currently. Maybe we could allow the user to pass a custom Meilisearch PHP Client in the config |
This would be a great addition. However, according to this issue where I explain the context, this repo will not have any new addition that will be not consistent with larvel/scout |
Hello @desaintflorent, I'm not sure this is what you asked for, but based on what @hi019 said, you can override the MeilisearchServiceProvider to use a custom http client. example: php artisan make:provider MeilisearchServiceProvider <?php
namespace App\Providers;
use MeiliSearch\Client;
class MeilisearchServiceProvider extends \Meilisearch\Scout\MeilisearchServiceProvider
{
public function register()
{
parent::register();
$this->app->singleton(Client::class, function () {
return new Client(config('meilisearch.host'), config('meilisearch.key'), new \GuzzleHttp\Client(['timeout' => 0.01]));
});
}
} In you 'providers' => [
// Other Service Providers
App\Providers\MeilisearchServiceProvider::class,
], Then, you should disable Meilisearch from being auto-discovered by adding the following to your composer.json ...
"extra": {
"laravel": {
"dont-discover": [
"meilisearch/meilisearch-laravel-scout"
]
}
},
... And if I don't miss something you should be good, the timeout will throw a try {
$movies = Movie::search('b')->get();
} catch (\MeiliSearch\Exceptions\CommunicationException $e) {
// do something
} If someone has a better option, I'll be glad to read it 😄 |
@shokme you should probably register the provider in app.php instead: https://laravel.com/docs/8.x/providers#registering-providers |
Indeed, I took the example from telescope local installation but you are right, I also think this is better. |
Thank's all for your help ! @shokme your example is working perfectly, I understood your code but It would have taken me lots of time to figure this out :) So thank's a lot for your help. Juste one thing, when I disable Meilisearch from being auto-discovered I had an error when running a search ( "Driver [meilisearch] not supported." ) |
I tried to reproduce your error and the only way was by not extending But, the code I showed to you is mostly from telescope package. So "dont-discover" will not register the package by default and allow you to load it when needed. my mistake, you can avoid this. Now about By the way, today laravel-scout 9 has been released with the support of meilisearch as first party package, you might want to use it, the code of this package has been merge inside scout so it won't change anything for you. |
I created a DigitalOcean droplet following your great tutorial, and I'm using it successfully with Laravel 👌
The only problem I have is when the server is down ( stopped manually or CPU at more than 100% ).
I can't find where I could set a short timeout so I could display an error ?
Right now it's loading indefinitely waiting for a response from the dead server.
The text was updated successfully, but these errors were encountered: