1

I'm new to Cypher and NEO4J in general, but I can't seem to google my way out of this one.

I have a graph like this:

The graph

What I want is to discover every path to the Teal node (ID 75) with one of the orange nodes as a starting point. All edges on orange nodes are outgoing with type "LINKED_BY_USER". So in this specific scenario, for node 73 I would want to have the following paths returned

  • 73 > 72 > 71 > 75
  • 73 > 72 > 76 > 75
  • 73 > 72 > 76 > 77 > 78 > 75

With this query: MATCH (e:Orange {Id: "73"})-[:LINKED_BY_USER*]-(e2:Teal) RETURN e2, count(*)

I get a count of 5, which I don't understand. Is it finding paths where it goes through 75 and then circles back? If so, shouldn't I get way more than 5 or is there some sort of cycle detection that stops when it detects a cycle? I guess in that case what I would need is a way to stop looking for paths as soon as the a goal node of type Teal is in the path? How would I do that? Thanks in advance.

bech
  • 627
  • 5
  • 22
  • 2
    Michael Hunger had a nice solution for this problem here - http://stackoverflow.com/questions/13767748/returning-only-simple-paths-in-neo4j-cypher-query. If you add "path=" in your match statement and then add a this where clause "WHERE ALL(n in nodes(path) where 1=length(filter(m in nodes(path) where m=n)))" it should work as you expect – Dave Bennett Mar 09 '15 at 19:15
  • Thank you Dave (And Michael :D), this did exactly what I needed. – bech Mar 10 '15 at 09:16

0 Answers0