-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneo4jConnect.php
More file actions
29 lines (20 loc) · 870 Bytes
/
neo4jConnect.php
File metadata and controls
29 lines (20 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
require_once 'vendor/autoload.php';
use GraphAware\Neo4j\Client\ClientBuilder;
$client = ClientBuilder::create()
->addConnection('default', 'http://neo4j:password@localhost:7474') // Example for HTTP connection configuration (port is optional)
->addConnection('bolt', 'bolt://neo4j:password@localhost:7687') // Example for BOLT connection configuration (port is optional)
->build();
$result = $client->run("MATCH (from:Page {title:\"" . $_REQUEST['title'] . "\"}), (to:Page {title:\"Adolf Hitler\"}) ,
path = shortestPath((from)-[:Link*]->(to))
RETURN path");
// get the first or (if expected only one) the only record
$record = $result->firstRecord();
$path = $record->values()[0];
$nodes = array();
foreach($path->nodes() as $node ) {
$title = $node->values()["title"];
array_push($nodes,$title);
}
echo json_encode($nodes);
exit();