问题
I'm trying to create a cypher query that returns me the nodes connected by a given range of hops (i.e. 1..5), where all the relationships between these hops share a same attribute value, without specifying this attribute.
So I would like to do something like
MATCH (a {type: 'cin1'})-[rels:Next*1.. {value: 1}]->(b {type: 'cancer'})
RETURN (a), (b)
But without specifying that the value on the edges should be one, they just need to be equal among all the edges in the hopping process.
回答1:
I would add an upper bound to your path. Or use (all)shortestPath(s)
Also make sure to look up a
and b
by indexed label + property combination.
And then you can use a predicate on the relationships-collection that forms your path.
MATCH (a:Label {type: 'cin1'})
MATCH (b:Label {type: 'cancer'})
MATCH shortestPath((a)-[rels:Next*1..20]->(b))
WHERE ALL(r in tail(rels) WHERE (head(rels)).value = r.value)
RETURN (a), (b)
来源:https://stackoverflow.com/questions/38095528/neo4j-cypher-query-to-get-nodes-connected-by-paths-with-the-same-generic-attribu