Moziz Carayol
Moziz Carayol

Reputation: 31

Any recommended PHP package for redisSearch?

I thought, surely there must be php developers out there who use redisSearch. I have only seen two packages for this RedisSearch-php by Ethan Hann and php-redisearch by MCFJA. They return empty documents and php-redisearch by MCFJA is not beneficial since it uses a Predis client (not really ideal for large applications in production).

Please is there any Laravel/PHP developer who is using redissearch and making progress. I'd be hugely appreciative of any advice and help. Thanks.

    $redis = new \Predis\Client([
        'scheme' => 'tcp',
        'host'   => '127.0.0.1',
        'port'   => 6379,
    ]);

    $builder = new \MacFJA\RediSearch\Index\Builder($redis);

    // Field can be create in advance
    $address = new \MacFJA\RediSearch\Index\Builder\GeoField('address');

    $builder
        ->withName('person')
        ->addField($address)
        // Or field can be create "inline"
        ->addTextField('lastname', false, null, null, true)
        ->addTextField('firstname')
        ->addNumericField('age')
        ->create();

    $index = new \MacFJA\RediSearch\Index('person', $redis);
    $index->addDocumentFromArray([
        'firstname' => 'Joe',
        'lastname' => 'Doe',
        'age' => 30,
        'address' => '40.689247,-74.044502'
    ]);
    
    $search = new \MacFJA\RediSearch\Search($redis);

    $results = $search
        ->withIndex('person')
        ->withQuery('Doe')
        ->withHighlight(['lastname'])
        ->withScores()
        ->search();

    return $results;  // returning empty arrays

Upvotes: 1

Views: 278

Answers (1)

MacFJA
MacFJA

Reputation: 46

The version 2.0.0 of macfja/redisearch is finally out.

This version have (built-in) support for multiple Redis provider. It should have the most common ones, and adding a new one is pretty simple.


And for the empty document list, maybe it's cause by the inverted coordinate (should be [longitude],[latitude])

Upvotes: 1

Related Questions