Skip to content

Instantly share code, notes, and snippets.

@Dalamar42
Created March 10, 2016 18:14
Show Gist options
  • Save Dalamar42/1ec93cd74b01c145e7bd to your computer and use it in GitHub Desktop.
Save Dalamar42/1ec93cd74b01c145e7bd to your computer and use it in GitHub Desktop.
PROFILE
MATCH (n:Label{ id:1} )
WITH n AS entry_node, collect(n) AS nodes_found_blue, collect(n) AS nodes_to_visit
UNWIND nodes_to_visit AS n
MATCH (n)-[:REL]-(target_node)
WHERE target_node = entry_node OR NOT target_node IN nodes_found_blue
WITH entry_node, nodes_found_blue + collect(DISTINCT target_node) AS nodes_found_green,
collect(DISTINCT target_node) AS nodes_to_visit
UNWIND nodes_to_visit AS n
MATCH (n)-[:REL]-(target_node)
WHERE target_node = entry_node OR NOT target_node IN nodes_found_green
WITH entry_node, nodes_found_green + collect(DISTINCT target_node) AS nodes_found_blue,
collect(DISTINCT target_node) AS nodes_to_visit
UNWIND nodes_found_blue AS n
RETURN DISTINCT n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment