Order by relationship properties neo4j

本小妞迷上赌 提交于 2019-12-10 20:54:29

问题


Using Neo4j 1.9.3 -

I want to create a music program listing. On a given program there may be three pieces being performed. Each piece has a composer associated with them, and may appear on many different programs, so I can't put sequence numbers on the piece nodes.

I assume I can create the program, with relationships to each piece like so:

(program1)-[:PROGRAM_PIECE {program_seq: 1}]->(piece1)
(program1)-[:PROGRAM_PIECE {program_seq: 2}]->(piece2)
(program1)-[:PROGRAM_PIECE {program_seq: 3}]->(piece3)

My question is, how do I query the graph so that the pieces are in order of the relationship property program_seq? I'm fine using ORDER BY with node properties, but have not been successful with relationships (story of my life...)


回答1:


If you like it, lock it down: that is, bind it to a variable. Then you can use ORDER BY the same way you would with node properties. If you have retrieved your program as (program1) you can do something like

MATCH (program1)-[r:PROGRAM_PIECE]->(piece1)
  RETURN program1, r, piece1
  ORDER BY r.program_seq



回答2:


I have done the same thing recently to keep track of chess moves in a particular game. It is the same thing as node properties.

start program = node(*) // or better yet, use a real index query to find the program
match (program)-[program_piece:PROGRAM_PIECE]->(piece)
return program, piece
order by program_piece.program_seq


来源:https://stackoverflow.com/questions/19232350/order-by-relationship-properties-neo4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!