1
I followed this tutorial to do the following:
echo "<h2>Encontre a rota mais curta da cidade A para a cidade B</h2>";
$query4 = 'MATCH p = (a {name: \'Palo Alto\'})-[r*2..5]->(b {name: \'Santa Clara\'}) WHERE NOT(a-->b) WITH p.name, relationships(p.name) AS rcoll RETURN a.name, b.name, p.name, reduce(totalDistance=0, x IN rcoll| totalDistance + x.distance) AS totalDistance ORDER BY totalDistance LIMIT 5';
$result4 = $client->run($query4);
$record4 = $result4->getRecord();
echo '<b>' . $record4->get('a.name') . '</b>';
foreach ($result4->getRecords() as $records4)
{
echo ' ⇢ ' . $records4->get('p.name');
}
echo '<b>' . $record4->get('b.name') . '</b>';
I tried the name of the cities, using the p.name
of MATCH p
.
Similar to $query4 = 'MATCH (a {name: \'Palo Alto\'})-[r*2..5]->(p) RETURN a.name, p.name LIMIT 5';
that worked, only that wanted to catch the city of Palo Alto to Santa Clara using the shortest route and the total distance because this result gave from Palo Alto to Milpitas for lack of shorter route and total distance.
Maybe I can help with the Neo4j and the consultation part, but I would need you to be a little clearer about your problem. I believe I don’t fully understand what you’re trying to do.
– Bruno Peres
The code
''MATCH p = (a {name: \'Palo Alto\'})-[r*2..5]->(b {name: \'Santa Clara\'}) WHERE NOT(a-->b) WITH p.name, relationships(p.name) AS rcoll RETURN a.name, b.name, p.name, reduce(totalDistance=0, x IN rcoll| totalDistance + x.distance) AS totalDistance ORDER BY totalDistance LIMIT 5''
did not work in Neo4j. ButMATCH (a {name: \'Palo Alto\'})-[r*2..5]->(p) RETURN a.name, p.name LIMIT 5
worked but picked the wrong cities because it used the long route.– Gustavo Reis