I am getting started with Neo4j and wondering about finding the nodes 
connected to another node from at most k edges (friend of a friend of a 
friend ... up to k times). I will illustrate with the example from the 
tutorial in Neo4j itself (I put graph creation commands are at the bottom).

match (e {name:"Emil"})-[*1..2]-(p)
return DISTINCT e, p;

This query would return nodes connected to Emil and nodes connected to 
those nodes. My issue is that it seems this enumerates EVERY path of length 
1-2 from Emil, though I don't care about enumerating all paths. This is an 
issue in large, dense graphs as the complexity becomes overwhelming. Based 
on my testing, it seems DISTINCT is a post-processing step that does not 
affect the runtime of the query, though it will eliminate the redundant 
output. Is that correct?

My main question, is there a way to form a Cypher query for this problem so 
that I am not traversing all the unique paths and the complexity can be 
reduced? Please let me know if I have a misunderstanding somewhere as well.


Best,
Steve


---- Commands to create the graph -----
 CREATE (ee:Person { name: "Emil", from: "Sweden", klout: 99 })
 MATCH (ee:Person) WHERE ee.name = "Emil"
 CREATE (js:Person { name: "Johan", from: "Sweden", learn: "surfing" }),
 (ir:Person { name: "Ian", from: "England", title: "author" }),
 (rvb:Person { name: "Rik", from: "Belgium", pet: "Orval" }),
 (ally:Person { name: "Allison", from: "California", hobby: "surfing" }),
 (ee)-[:KNOWS {since: 2001}]->(js),(ee)-[:KNOWS {rating: 5}]->(ir),
 (js)-[:KNOWS]->(ir),(js)-[:KNOWS]->(rvb),
 (ir)-[:KNOWS]->(js),(ir)-[:KNOWS]->(ally),
 (rvb)-[:KNOWS]->(ally)

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to neo4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to