I am attempting to generate a database using MERGE
statements through Neo4JPHP. All of my queries are using MERGE
; however, it is generating separate nodes every time, resulting in massive duplication.
The queries are run within a single transaction. I've removed the surrounding code to focus on the queries:
$transaction = $client->beginTransaction();
while(...) {
$pq = new Query($client, 'MERGE (n:Page {url:"'.$page.'"}) SET n.title="'.$title.'"');
$transaction->addStatements(array($pageQuery));
$h1Query = new Query($client, 'MATCH (n:Page {url:"'.$page.'"}) SET n.h1s = "['.implode(", ", $h1s).']"');
$transaction->addStatements(array($h1Query));
$scriptQuery = new Query($client, 'MATCH (n:Page {url:"'.$page.'"}) MERGE (n)-[:CONTAINS_SCRIPT]->(s:Script {url:"'.$s.'"})');
$transaction->addStatements(array($scriptQuery));
$styleQuery = new Query($client, 'MATCH (n:Page {url:"'.$page.'"}) MERGE (n)-[:CONTAINS_STYLESHEET]->(s:StyleSheet {url:"'.$s.'"})');
$transaction->addStatements(array($styleQuery));
$otherPageQuery = new Query($client, 'MATCH (n:Page {url:"'.$page.'"}) MERGE (n)-[:LINKS_TO]->(m:Page {url:"'.$match.'"})');
$transaction->addStatements(array($otherPageQuery));
}
$transaction->commit();
Now, after running this across a couple of pages, it comes up with 6 copies of the same Page
s, one with title
and h1s
elements, and the rest without.
I also tried using CREATE UNIQUE
, but this gave an error that the syntax wasn't supported.
I am running Neo4j 2.0.1. Any suggestions?