tntsearch
tntsearch copied to clipboard
Undefined offset: 0 in filesystemMapIdsToPaths(...)
I am getting this error:
PHP Notice: Undefined offset: 0 in /home/.../vendor/teamtnt/tntsearch/src/TNTSearch.php on line 408
The error happens at the call of $tnt->search(...)
in the following example, even though I do get results.
// TNT Search
$indexName = 'test.index';
$createIndex = true;
$tntConfig = [
"driver" => 'filesystem',
"location" => __DIR__.'/tntsearch/dummysource/',
"extension" => "txt",
'storage' => __DIR__.'/tntsearch/indexes/'
];
$tnt = new TNTSearch;
$tnt->loadConfig($tntConfig);
if( $createIndex ){
// Creating a NEW index. Empty old one first:
if (file_exists($tnt->config['storage'].$indexName)) {
unlink($tnt->config['storage'].$indexName);
touch($tnt->config['storage'].$indexName);
}
$indexer = $tnt->createIndex($indexName);
$indexer->run();
$indexer->insert(['id' => 0, 'content' => 'new awesome article about php']);
$indexer->insert(['id' => 1, 'content' => 'another article about php']);
$indexer->insert(['id' => 2, 'content' => 'read this one because it is cool.']);
$indexer->insert(['id' => 3, 'content' => 'some stuff about interesting things']);
}
$tnt->selectIndex($indexName);
$results = $tnt->search('article', 4);
var_dump($results);
Running this code gives the following correct output (so it is working):
array(2) {
[0]=>
NULL
[1]=>
NULL
}
I had the same problem, but found out that it was caused by uneven number of fields when inserting data. Make sure your array has the same keys for each insert.
Good thought @akizor ... but my inserts in the sample code above are identical.
Still getting this error in latest 2.1 version.
In the src/TNTSearch.php file, this function:
public function filesystemMapIdsToPaths($docs)
Doesn't handle the case when $index
does not exist in $res
.