Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search node query #2

Open
coxy17 opened this issue Feb 23, 2024 · 2 comments
Open

Search node query #2

coxy17 opened this issue Feb 23, 2024 · 2 comments
Assignees
Labels

Comments

@coxy17
Copy link

coxy17 commented Feb 23, 2024

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')

@rafageist rafageist self-assigned this May 18, 2024
@coxy17
Copy link
Author

coxy17 commented Oct 27, 2024

Hi, is there any update to this? thanks

@rafageist
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants