Closed itmeicn closed 2 years ago
$builder=new \MacFJA\RediSearch\IndexBuilder();
$res=$builder->setIndex($this->name)->addPrefixes('finance_fun_daylog:')
->addTagField('zid',null,true)
->addTextField('bank_number',false,2,null,true,false)
->addTextField('today',false,2,null,true,false)
->addNumericField('shou')
->addNumericField('zhi')
->addNumericField('bank_balance')
->create($this->searchConnect);
dump($res);//1
create index is ok
Can you dump the content of $rawDefinitions
?
/**
* @return null|array<string,mixed>|mixed
*/
public function getIndexDefinition(?string $key = null)
{
$rawDefinitions = self::getValue($this->rawLines, 'index_definition');
dd($rawDefinitions); // Add this line
assert(is_array($rawDefinitions));
$data = self::getPairs($rawDefinitions);
if (!is_string($key)) {
return $data;
}
return $data[$key] ?? null;
}
$rawDefinitions = self::getValue($this->rawLines, 'index_definition'); dump($rawDefinitions);exit(); is result:null. $a=$cacheRedis->rawCommand('ft.info','finance_fun_daylog'); dump($a);//The result is the same as the -rawLines: value,I use the open source RediSearch2.4.9. I use phpredis.
today,It's ok useing old version1.4, I use the new version 2.1.2 to work with predis1.1.10,But 2.1.2 and phpredis5.3.3 have errors. Common use of php8.0.
I see in the result of your FT.INFO
request that all even value is equal to true
instead of the name of the data.
So it's impossible to find the right data (even result lines are the data key, and odd result lines are the data value)
I can't reproduce yet your case.
But as a work around for now you can just call redis HSET
:
// instead of
/*
$res=$index->addDocumentFromArray([
'zid'=>'553',
'bank_number'=>'666',
'today'=>'2022-07-21',
'shou'=>0,
'zhi'=>0,
'bank_balance'=>0
],$this->name.':'.'553');
*/
// Do this
$this->searchConnect->executeRaw(
'HSET',
$this->name . ':' . '553',
'zid', '553',
'bank_number', '666',
'today', '2022-07-21',
'shou', 0,
'zhi', 0,
'bank_balance', 0
);
It's pretty much what do the addDocumentFromArray
, except that addDocumentFromArray
try to be smart and add document hash with the good prefix if you don't provide it yourself. Which is not your case
vendor/macfja/redisearch/src/Redis/Client/PhpredisClient.php
public function execute(Command $command)
{
$arguments = $command->getArguments();
if (0 === count($arguments)) {
/** @psalm-suppress TooFewArguments */
$rawResponse = $this->redis->rawCommand($command->getId());
} else {
// add line start
if ($command->getId()=='FT.INFO'){
$this->redis->setOption(\Redis::OPT_REPLY_LITERAL, true); //add this line solve the problems
}
// add line end,ft.info can get the correct value
$rawResponse = $this->redis->rawCommand($command->getId(), ...$arguments);
}
return $command->parseResponse($rawResponse);
}
ths
is error:
assert(is_array($rawDefinitions));