MacFJA/php-redisearch

According to the documentation example, the query highlighting settings will run incorrectly

Closed this issue · 2 comments

My PHP : PHP 7.4.28 (cli)
use : tag/2.1.1

image

The error is as follows:

PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function MacFJA\RediSearch\Redis\Command\Search::setHighlight(), 1 passed in /Code/redisearch-php/nindex.php on line 58 and exactly 3 expected in /Code/redisearch-php/vendor/macfja/redisearch/src/Redis/Command/Search.php:164
Stack trace:
#0 /Code/redisearch-php/nindex.php(58): MacFJA\RediSearch\Redis\Command\Search->setHighlight(Array)
#1 {main}
  thrown in /Code/redisearch-php/vendor/macfja/redisearch/src/Redis/Command/Search.php on line 164

The interface prototype is as follows
https://github.com/MacFJA/php-redisearch/blob/main/src/Redis/Command/Search.php

/**
     * @param null|array<string> $fields
     *
     * @return $this
     */
    public function setHighlight(?array $fields, ?string $openTag, ?string $closeTag): self
    {
        $this->options['highlight']
            ->setDataOfOption('type', true)
            ->setDataOfOption('fields', $fields)
            ->setTags($openTag, $closeTag)
        ;

        return $this;
    }

Correct execution should be

$search
    ->setIndex('person')
    ->setQuery('Doe')
     ->setHighlight(['lastname'],null,null)
    ->setWithScores();
$results = $client->execute($search);

So that I can execute successfully.

image

Documentation omissions ?

Not an error in the documentation, it's rather an issue with the code.

The parameter #2 and #3 should be default to null, as the open and close tag are completely optional from the RediSearch documentation

ths