【问题标题】:How to use Apache Solr with Laravel 9如何在 Laravel 9 中使用 Apache Solr
【发布时间】:2022-08-04 17:38:00
【问题描述】:

我是 Apache Solr 和 Laravel 的新手。我想创建一个使用 Apache Solr 作为搜索平台的网站,并使用 Laravel 作为我的 PHP 框架。我已经遵循了一些在谷歌搜索时发现的指南:

  1. https://petericebear.github.io/laravel-php-solarium-integration-20160725/
  2. https://teguharief.wordpress.com/2018/05/01/creation-search-engine-on-laravel-sites-using-solr/

    我已按照每个步骤进行操作,并被困在 Solarium ServiceProvider.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 已经在配置中,如图所示:

    config/solr.php

    然后我得到了这个错误。

    Solarium\\Core\\Client\\Client::__construct(): 参数 #1 ($adapter) 必须是 Solarium\\Core\\Client\\Adapter\\AdapterInterface 类型,给定数组,在 ...

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

  • 阅读文档。由于您使用的是日光浴室 6,因此使用正确的参数 github.com/solariumphp/solarium 为事件调度程序实例化它,请使用照明
  • 你能告诉我如何用正确的参数实例化它吗?即使在阅读文档后我也很迷茫

标签: php laravel solr


【解决方案1】:
 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']);
        });
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-18
    • 2021-12-23
    • 2015-01-23
    • 1970-01-01
    • 2022-12-11
    • 1970-01-01
    • 1970-01-01
    • 2022-06-21
    相关资源
    最近更新 更多