cancel
Showing results forΒ
Did you mean:Β

Head's Up! Site maintenance this Wednesday, February 1. Disruptions expected as we migrate the forums.

## Create all pathes where each path has any condition

Node

I have a such question:
I have nodes which are connected in a such way:

Now I wanna find all pathes from main to every leaf with condition that every path contains only one direction etc:
main -> west -> west -> leaf
main -> east -> east -> leaf
and return all nodes in each way.
In one query, i mean
I can do something like that for one path
match p=(start:Square)-[d:HOP*3]->(end:Square)
where start.row=4 and start.col=4 and
(all (x in relationships(p) where x.type="NORTH"))
return p;

1 ACCEPTED SOLUTION
Graph Fellow

@dimachichlov

If I got it, the dataset is something like this:

create (n:Square) with n
create (n)-[:HOP {type: 'NORTH'}]->(:Square)-[:HOP {type: 'NORTH'}]->(:Square)-[:HOP {type: 'NORTH'}]->(:Square)
create (n)-[:HOP {type: 'EAST'}]->(:Square)-[:HOP {type: 'EAST'}]->(:Square)-[:HOP {type: 'EAST'}]->(:Square)
create (n)-[:HOP {type: 'SOUTH'}]->(:Square)-[:HOP {type: 'SOUTH'}]->(:Square)-[:HOP {type: 'SOUTH'}]->(:Square)
create (n)-[:HOP {type: 'WEST'}]->(:Square)-[:HOP {type: 'WEST'}]->(:Square)-[:HOP {type: 'WEST'}]->(:Square)

In this case, you could search all "coordinate" paths with this query:

MATCH (start:Square) with start
MATCH north=(start)-[d:HOP*3 {type: "NORTH"}]->(end:Square) // search rels with prop type "NORTH"
WITH north, start
MATCH south=(start)-[d:HOP*3 {type: "SOUTH"}]->(end:Square) // search rels with prop type "SOUTH"
WITH north, south, start
MATCH east=(start)-[d:HOP*3 {type: "EAST"}]->(end:Square)
WITH north, south, east, start
MATCH west=(start)-[d:HOP*3 {type: "WEST"}]->(end:Square)
RETURN DISTINCT north, east, west, south
Graph Fellow

@dimachichlov

If I got it, the dataset is something like this:

create (n:Square) with n
create (n)-[:HOP {type: 'NORTH'}]->(:Square)-[:HOP {type: 'NORTH'}]->(:Square)-[:HOP {type: 'NORTH'}]->(:Square)
create (n)-[:HOP {type: 'EAST'}]->(:Square)-[:HOP {type: 'EAST'}]->(:Square)-[:HOP {type: 'EAST'}]->(:Square)
create (n)-[:HOP {type: 'SOUTH'}]->(:Square)-[:HOP {type: 'SOUTH'}]->(:Square)-[:HOP {type: 'SOUTH'}]->(:Square)
create (n)-[:HOP {type: 'WEST'}]->(:Square)-[:HOP {type: 'WEST'}]->(:Square)-[:HOP {type: 'WEST'}]->(:Square)

In this case, you could search all "coordinate" paths with this query:

MATCH (start:Square) with start
MATCH north=(start)-[d:HOP*3 {type: "NORTH"}]->(end:Square) // search rels with prop type "NORTH"
WITH north, start
MATCH south=(start)-[d:HOP*3 {type: "SOUTH"}]->(end:Square) // search rels with prop type "SOUTH"
WITH north, south, start
MATCH east=(start)-[d:HOP*3 {type: "EAST"}]->(end:Square)
WITH north, south, east, start
MATCH west=(start)-[d:HOP*3 {type: "WEST"}]->(end:Square)
RETURN DISTINCT north, east, west, south