Giter VIP home page Giter VIP logo

Comments (8)

shokme avatar shokme commented on June 2, 2024 3

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.

shokme avatar shokme commented on June 2, 2024 1

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.

curquiza avatar curquiza commented on June 2, 2024

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.

hi019 avatar hi019 commented on June 2, 2024

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.

curquiza avatar curquiza commented on June 2, 2024

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.

hi019 avatar hi019 commented on June 2, 2024

@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 avatar shokme commented on June 2, 2024

@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.

desaintflorent avatar desaintflorent commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.