Comments (8)
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 config/app.php
'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 MeiliSearch\Exceptions\CommunicationException
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 😄
from meilisearch-laravel-scout.
I tried to reproduce your error and the only way was by not extending \Meilisearch\Scout\MeilisearchServiceProvider
from App\Providers\MeilisearchServiceProvider
.
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 App\Providers\MeilisearchServiceProvider
, If I'm right and you don't extend the provider from the package, it works, good. But to be honest I'm not sure how it will be handled behind the scene.
My guess is Meilisearch package will be registered and then the custom provider will be registered and override the Client singleton. Your choice to extend or not on that one as I'm not able to give a clear answer.
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.
from meilisearch-laravel-scout.
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.
If someone knows a workaround, feel free to share it on this issue 🙂
Glad to read you liked the DO tutorial on our docs, we do our best to provide integrations with nice documentation!
from meilisearch-laravel-scout.
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
from meilisearch-laravel-scout.
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
We might create a new repo that will be more a meilisearch-laravel-scout-extended plugin, and we will integrate this kind of possibility into it. I let this issue open since it's a good idea of improvement for the next repo (or the next version of this repo).
from meilisearch-laravel-scout.
@shokme you should probably register the provider in app.php instead: https://laravel.com/docs/8.x/providers#registering-providers
from meilisearch-laravel-scout.
@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.
from meilisearch-laravel-scout.
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." )
But by not disabling it, it's working on my local environment. Will try in production soon.
Why it's important to disable it ?
from meilisearch-laravel-scout.
Related Issues (20)
- search()->get() returns a maximum of 20 items HOT 1
- A primary key is already present. It's impossible to update it HOT 2
- using FacetFilters HOT 3
- cant find any good example tutorial ,correct me if iam doing wrong HOT 4
- The future of this repo HOT 17
- Delay for index new records HOT 1
- [DX] Easy index configuration HOT 2
- Creating index using php artisan not working HOT 7
- cant use toSearchableArray method HOT 3
- Include facetsDistribution in paginate() response? HOT 1
- Skip searching by ID HOT 5
- How to deploy and use laravel-scout and Meilisearch to ec2 instance HOT 5
- Update of existing records HOT 4
- Downgrading Meilisearch to version compatible with database HOT 1
- Engine uses the eloquent getScoutKey() to get key values but uses getKeyName() to get the name of the key HOT 2
- Getting an error when meilisearch service is not run HOT 1
- paginateRaw() returns wrong amount of total items HOT 4
- Laravel native support announced HOT 1
- One Model not importing HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meilisearch-laravel-scout.