I have installed the plugin MacFJA/php-redisearch using the following command
composer require macfja/redisearch
Issue:
Complete code:
<?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();
}
}
Can someone share why the issue is thrown?
As @NicoHaase said (and here also), MacFJA\RediSearch\Redis\Client\ClientFacade
is not available in versions 1.x, and as for now, the version installed by Composer is the version 1.4.0
.
The next version (that will be 2.0.0
) is not ready yet, but is not far away. It's this version that have the class MacFJA\RediSearch\Redis\Client\ClientFacade
.
But the version 1.4.0
can be used in Laravel as well.
The documentation is here: https://github.com/MacFJA/php-redisearch/tree/1.4.0#readme
But to summarize it should be something like:
<?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
}
}
You can also look at this lib: macfja/redisearch-integration. Its goal is to reduce a part of the boilerplate and add PHP object mapping (like Doctrine ORM)