Open coxy17 opened 8 months ago
Hi, is there any update to this? thanks
Hello,
search()
is not available in version 2.0.0. However, I am working on the new version 3.0.0 and you can try this feature in the master branch.
This is an example that receives a phrase from the command line. Create a file with the following code:
use divengine\nodes;
// include "../src/nodes.php";
include "vendor/autoload.php";
$phrase = $_SERVER['argv'][1];
$db = new nodes("database/contacts");
$db->delNodes();
// 1. Create indexer before create nodes
$db->addIndexer('name_index', function ($node) {
return $node['name'];
});
// 2. Create the nodes
$db->addNode([
"name" => "John Doe",
"age" => 30,
"city" => "New York"
]);
$db->addNode([
"name" => "Jane Doe",
"age" => 25,
"city" => "New York"
]);
$db->addNode([
"name" => "John Smith",
"age" => 35,
"city" => "Florida"
]);
$db->addNode([
"name" => "Jane Smith",
"age" => 40,
"city" => "Florida"
]);
$db->addNode([
"name" => "Peter Nash",
"age" => 25,
"city" => "NY"
]);
$db->addNode([
"name" => "Carl Nash",
"age" => 35,
"city" => "NY"
]);
$db->addNode([
"name" => "Peter Smith",
"age" => 15,
"city" => "California"
]);
$db->addNode([
"name" => "Carl Smith",
"age" => 45,
"city" => "California"
]);
// 3. Then search and get the indexes
$indexes = $db->search($phrase);
// 4. Load the nodes
foreach ($indexes as $indexId => $index) {
$node = $db->getNode($index['id']);
echo "- {$node['name']}\n";
}
And then:
$ php test.php doe
- John Doe
- Jane Doe
$ php test.php john
- John Doe
- John Smith
Regards
Hi I tried to search for a node using a partial or full string, but not having any luck returning a node. Is this supported?
e.g. $db->search('something')