Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-01-2021 12:04 AM
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;
Solved! Go to Solution.
12-01-2021 07:25 AM
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
12-01-2021 07:25 AM
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
All the sessions of the conference are now available online