Skip to content
Advertisement

Issue in integrating php-redisearch with laravel 8

I have installed the plugin MacFJA/php-redisearch using the following command

composer require macfja/redisearch

Issue:

enter image description here

Complete code:

<?php

namespace AppConsoleCommands;

use IlluminateConsoleCommand;
use IlluminateSupportFacadesLog;
use IlluminateSupportFacadesRedis;
use DateTime;
use FKRediSearchRediSearchSetup;
use MacFJARediSearchRedisClientClientFacade;

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?

Advertisement

Answer

As @NicoHaase said (and here also), MacFJARediSearchRedisClientClientFacade 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 MacFJARediSearchRedisClientClientFacade.


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 AppConsoleCommands;

use IlluminateConsoleCommand;
use IlluminateSupportFacadesLog;
use IlluminateSupportFacadesRedis;
use DateTime;
use PredisClient;
use MacFJARediSearchSearch;

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)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement