php-redisearch 与 laravel 8 整合的问题

Issue in integrating php-redisearch with laravel 8

我已经使用以下命令安装了插件 MacFJA/php-redisearch

composer require macfja/redisearch

问题:

完整代码:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use DateTime;
use FKRediSearch\RediSearch\Setup;
use MacFJA\RediSearch\Redis\Client\ClientFacade;

class CommandName extends Command
{
    protected $signature = 'command:commandName';
    protected $description = 'Command description';
    public function __construct()
    {
        parent::__construct();
    }
    public function handle()
    {
        $clientFacade = new ClientFacade();
    }
}

有人可以分享为什么抛出这个问题吗?

正如@NicoHaase所说(和here also),MacFJA\RediSearch\Redis\Client\ClientFacade在版本1.x中不可用,而目前,Composer安装的版本是[=12] =].

下一个版本(即 2.0.0)尚未准备好,但已经不远了。这个版本有 class MacFJA\RediSearch\Redis\Client\ClientFacade.


但是 1.4.0 版本也可以在 Laravel 中使用。

文档在这里:https://github.com/MacFJA/php-redisearch/tree/1.4.0#readme

但总结起来应该是这样的:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use DateTime;
use Predis\Client;
use MacFJA\RediSearch\Search;

class CommandName extends Command
{
    protected $signature = 'command:commandName';
    protected $description = 'Command description';
    public function __construct()
    {
        parent::__construct();
    }
    public function handle()
    {
        $client = new Client(['scheme' => 'tcp', 'host' => 'localhost', 'port' => '6379', 'db' => 0]);
        $search = new Search($client);

        $results = $search
            ->withIndex('person')
            ->withQuery('Doe')
            ->withHighlight(['lastname'])
            ->withScores()
            ->search();
        // Do something with $result
    }
}

你也可以看看这个库:macfja/redisearch-integration。 它的目标是减少一部分样板并添加 PHP 对象映射(如 Doctrine ORM)