tntsearch icon indicating copy to clipboard operation
tntsearch copied to clipboard

Undefined offset: 0 in filesystemMapIdsToPaths(...)

Open syntaxseed opened this issue 7 years ago • 4 comments

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
}

syntaxseed avatar Feb 16 '18 14:02 syntaxseed

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.

akizor avatar Mar 09 '18 15:03 akizor

Good thought @akizor ... but my inserts in the sample code above are identical.

syntaxseed avatar Mar 09 '18 16:03 syntaxseed

Still getting this error in latest 2.1 version.

syntaxseed avatar Jun 19 '19 19:06 syntaxseed

In the src/TNTSearch.php file, this function:

public function filesystemMapIdsToPaths($docs)

Doesn't handle the case when $index does not exist in $res.

syntaxseed avatar Jun 19 '19 19:06 syntaxseed