Skip to content

Instantly share code, notes, and snippets.

@mebibou
Last active December 21, 2015 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mebibou/6260328 to your computer and use it in GitHub Desktop.
Save mebibou/6260328 to your computer and use it in GitHub Desktop.
simple map with shortcut
== The setup
This is a map that contains a 'shortcut' from s1 to s4 (without going through s2 and s3).
//setup
//hide
[source,cypher]
----
CREATE (s1:Stop {name:"First Stop"})
CREATE (s2:Stop {name:"Second Stop"})
CREATE (s3:Stop {name:"Third Stop"})
CREATE (s4:Stop {name:"Fourth Stop"})
CREATE (s5:Stop {name:"Fifth Stop"})
CREATE (s6:Stop {name:"Sixth Stop"})
CREATE (s7:Stop {name:"Seventh Stop"})
CREATE (s1)-[:STOPS_STOPS{lineId:1}]->(s2)
CREATE (s2)-[:STOPS_STOPS{lineId:1}]->(s1)
CREATE (s2)-[:STOPS_STOPS{lineId:1}]->(s3)
CREATE (s3)-[:STOPS_STOPS{lineId:1}]->(s2)
CREATE (s3)-[:STOPS_STOPS{lineId:1}]->(s4)
CREATE (s4)-[:STOPS_STOPS{lineId:1}]->(s3)
CREATE (s1)-[:STOPS_STOPS{lineId:1}]->(s4)
CREATE (s4)-[:STOPS_STOPS{lineId:1}]->(s1)
CREATE (s4)-[:STOPS_STOPS{lineId:1}]->(s5)
CREATE (s5)-[:STOPS_STOPS{lineId:1}]->(s4)
CREATE (s4)-[:STOPS_STOPS{lineId:1}]->(s6)
CREATE (s6)-[:STOPS_STOPS{lineId:1}]->(s4)
CREATE (s6)-[:STOPS_STOPS{lineId:1}]->(s7)
CREATE (s7)-[:STOPS_STOPS{lineId:1}]->(s6)
----
== Find the start and end points for `line1`
[source,cypher]
----
START stop = node(*)
MATCH line=(s1)-[r:STOPS_STOPS*]->(s2)
WHERE ALL (rel IN RELATIONSHIPS(line)
WHERE rel.lineId=1)
RETURN s1, s2, length(line) AS length
ORDER BY length DESC
----
//table
== Find all the stops for Line `1` to create a map
Here, all the stops that make up the line should be found in order to create a map in a way that lists the longest paths first.
[source,cypher]
----
MATCH line=(stop1)-[r:STOPS_STOPS*]->(stop2)
WHERE ALL (rel IN RELATIONSHIPS(line)
WHERE rel.lineId=1)
RETURN line, length(line) AS length
ORDER BY length DESC
----
//table
== console
//console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment