如何将Apache Solr与Laravel 9一起使用

jmo0nnb3  于 2022-10-21  发布在  Apache
关注(0)|答案(1)|浏览(155)

我对Apache Solr和Laravel是新手。我想创建一个使用Apache Solr作为搜索平台,使用Laravel作为PHP框架的网站。我已经在谷歌上找到了一些指南:
1.https://petericebear.github.io/laravel-php-solarium-integration-20160725/ l
1.https://teguharief.wordpress.com/2018/05/01/creation-search-engine-on-laravel-sites-using-solr/
我已经完成了每一步,并被困在SolariumServiceProvider.php
这是SolariumServiceProvider.php的代码

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Solarium\Client;

class SolariumServiceProvider extends ServiceProvider
{
    protected $defer = true;

    /**
     * Register any application services.
     *
     * @return  void
     */
    public function register()
    {
        $this->app->bind(Client::class, function ($app) {
            return new Client($app->['config']['solr']); <- What is the correct syntax?
        });
    }

    public function provides()
    {
        return [Client::class];
    }
}

Solr。php已经在配置中,如图所示:
i1 j2 k1 l
然后我得到了这个错误。

Solarium\Core\Client\Client::__construct():参数#1($adapter)必须是Solarium\ Core\客户端\adapter\adapter接口类型,数组给定,在…中调用

任何有经验集成laravel和Apache Solr的人都能帮我解决这个问题吗?

pn9klfpd

pn9klfpd1#

public function register()
    {
        $this->app->bind(Client::class, function ($app) {
            $adapter = new Solarium\Core\Client\Adapter\Curl();
            $eventDispatcher = new Symfony\Component\EventDispatcher\EventDispatcher();
            return new Client($adapter, $eventDispatcher, $app->['config']['solr']);
        });
    }

相关问题