יום חמישי, 30 במאי 2013

cypher variable length relationship

Note the demo db DataBase creation code can be found in prev posts.
Mark with an asterisk (*)
The following example gets all connected nodes in all levels:

  1: theCyperCode = "START Brusc=node(1) MATCH Brusc-[*]->(ConnectedNode) RETURN  ConnectedNode"
  2:          
  3: cypher.execute(graph_db, theCyperCode, row_handler=handle_row)


The results :
cypher query result:
(2 {"name":"John McClane"})
cypher query result:
(5 {"name":"Nakatomi Plaza"})
cypher query result:
(4 {"name":"Hans Gruber"})
cypher query result:
(5 {"name":"Nakatomi Plaza"})
Note that node 5 was visited twice and its apear twice in the result set

We can limit the depth by specifing a range in the form:[*MinDepth..MaxDepth]
for en example


  1: theCyperCode = "START Brusc=node(1) MATCH Brusc-[*2..3]->(ConnectedNode) RETURN  ConnectedNode"
  2: cypher.execute(graph_db, theCyperCode, row_handler=handle_row)

The result:
cypher query result:
(5 {"name":"Nakatomi Plaza"})
cypher query result:
(4 {"name":"Hans Gruber"})
cypher query result:
(5 {"name":"Nakatomi Plaza"})
Only the 2nd and the 3rd level were returned

אין תגובות:

הוסף רשומת תגובה