Created
November 11, 2012 01:26
-
-
Save jadell/4053297 to your computer and use it in GitHub Desktop.
Delete nodes using a cypher query in neo4jphp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(-1); | |
ini_set('display_errors', 1); | |
spl_autoload_register(function ($sClass) { | |
$sLibPath = __DIR__.'/../lib/'; | |
$sClassFile = str_replace('\\',DIRECTORY_SEPARATOR,$sClass).'.php'; | |
$sClassPath = $sLibPath.$sClassFile; | |
if (file_exists($sClassPath)) { | |
require($sClassPath); | |
} | |
}); | |
$client = new Everyman\Neo4j\Client(); | |
$numNodes = 1000; | |
for ($i=0; $i<$numNodes; $i++) { | |
$client->startBatch(); | |
$nodeA = $client->makeNode()->save(); | |
$nodeB = $client->makeNode()->setProperty('prop', 'xyz')->save(); | |
$rel = $nodeA->relateTo($nodeB, 'rel')->save(); | |
$client->commitBatch(); | |
} | |
$queryTemplate = "START n = node(*) MATCH n-[r:rel]-b WHERE has(b.prop) AND not(b.prop in {phparr}) DELETE b, r"; | |
$query = new Everyman\Neo4j\Cypher\Query($client, $queryTemplate, array( | |
// 'nodeId' => $nodeA->getId(), | |
'phparr' => array('zyx'), | |
)); | |
$query->getResultSet(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment