Reputation: 2545
I have a graph database where every node is having a relationship intersects
with the nodes that it intersects. Additionally, the intersects
has a property degrees
(angle at which the intersection of these two nodes happen).
I want to order the nodes which intersect a given node at a specified angle.
Since the intersection between two nodes is supplementary, I am saving only one relationship between the two nodes (example, (a)-[:intersects]->(b) and (b)-[:intersects]->(a) are similar things, but the angle will be different for the two, and this angle is supplementary). For example, if I need all cities intersecting City A at 45 degrees angle, the two queries are:
GRAPH.QUERY Nearby "MATCH (a:City { name: 'A' })-[t:intersects]->(b:City) return b.name, b.degrees ORDER BY abs(t.degrees - 45)"
GRAPH.QUERY Nearby "MATCH (a:City { name: 'A' })<-[t:intersects]-(b:City) return b.name, b.degrees ORDER BY abs(abs(t.degrees - 180) - 45)"
I want to combine these two queries in one (avoid the sorting in the client library). Is it possible to do it in redis graph? I was going to try (a)-[:intersects]-(b)
and use the case...when but seems like the support to get the src node is not available yet.
Any help would be really appreciated.
Upvotes: 1
Views: 123
Reputation: 879
Consider the following:
MATCH (a:City {name: 'A'})-[t0:intersects]->(b:City)
WITH a, collect({x:b, angle:abs(t0.degrees - 45)}) AS a_to_b
MATCH (a)<-[t1:intersects]-(c:City)
WITH a_to_b, collect({x:c, angle:abs(abs(t1.degrees - 180) - 45)}) AS c_to_a
WITH a_to_b + c_to_a AS intersections
UNWIND intersections AS city
RETURN city.x ORDER BY city.angle
Upvotes: 1