I have a neo4j graphdb that stores ordered collections of nodes (let's say Person nodes), and each of those people has a Talent node:
(p:Person)-[:HAS_TALENT]->(t:Talent)
I'm organizing a talent show, and have the schedule of the order in which people are going to perform:
(p:Person)-[:FOLLOWS*]->(q:Person)
I can write a query to return a path that represents the order in which the people perform, and when I return that path, the Person nodes show up in the order that they appear in the path. However, when I do a sub-query to return the talents that the people are performing, they no longer show up ordered by the path.
Is there a way to order nodes based on the order they appear in a path? I've tried using COLLECT
to get a list of Person nodes, but I can't seem to find a way to use that collection to get back an ordered list of Talent nodes.
My current path-query looks something like this, with a special start and end node so I know who's first and last. (I don't have the DB in front of me right now, so apologies if it's not spot-on):
MATCH p=(s:StartNode {side:"start"})-[:FOLLOWS*1..10]->(s:StartNode {side:"end"})
RETURN p
I've run through a lot of different options for retrieving the path from start to finish, and they have their pros and cons, but I can't find a way to retrieve the Talent nodes in the same order.
EDIT: It seems I may have over simplified my example scenario. The database I'm actually working with has multiple paths from start to finish through Person nodes, and I have a query to first select just a single path from start to finish before moving ahead to match Talent nodes. Apologies to @Dirk Horsten who answered the question I asked, but not the one I needed answered.
Since I'm editing this already, @Dave Bennett 's answer solved my problem because the unwind
function seems to keep the path's order intact for future MATCH clauses.