I'm reading through the book Graph Algorithms, and before running this query (page 60):
MATCH p=(email:Email {id:'6'})<-[:REPLY_TO*1..4]-(:Reply)<-[:SENT]-(replier)
RETURN replier.username AS replier, length(p) - 1 AS depth
ORDER BY depth
I received the following warning:
This feature is deprecated and will be removed in future versions.
Binding relationships to a list in a variable length pattern is deprecated. (Binding a variable length relationship pattern to a variable ('REPLY_TO') is deprecated and will be unsupported in a future version. The recommended way is to bind the whole path to a variable, then extract the relationships: MATCH p = (...)-[...]-(...) WITH *, relationships(p) AS REPLY_TO)
What modifications does the original query need to make it current?
MATCH p = (email:Email {id:'6'})<-[:REPLY_TO*1..4]-(:Reply)<-[:SENT]-(replier)
RETURN replier.username AS replier, length(relationships(p)) - 1 AS depth
ORDER BY depth
But there's a learning opportunity here; the query Neo4j proposes MATCH p = (...)-[...]-(...) WITH *, relationships(p) AS REPLY_TO, when would it be appropriate to use? What's a use-case for it?
Personaly, I use relationships(p) when for example I need to get all nodes of path, or to get all the properties of path. When you have a small path (2 relations and 3 nodes), you are not force to use it but it becomes necessary when you have longer path
@cobra I'm having a similar issue as Timothy, but still can't get your suggested query to work. I'm basically trying to find relationships within 2 hops but getting the following. Any ideas?
The function relationships(z) returns a list of relationships so you must use size(relationships(z)) if you want the size of the list. The function length() can be used directly on z since it's a path and not a list. So you there are size(relationships(z)) or length(z).