Neo4j常用查询语句整理

0

// 忽略属性
@Query("MATCH p=(a:RoomNode{roomId:$roomIdA})-[*..16]-(z:RoomNode{roomId:$roomIdZ}) RETURN p, LENGTH(p)")
// 指定属性
@Query("MATCH p=(a:RoomNode{roomId:$roomIdA})-[r:RoomRelationship*..16]-(z:RoomNode{roomId:$roomIdZ}) RETURN p, LENGTH(p)")
// 最短路径
@Query("MATCH (a:RoomNode{roomId:$roomIdA}), (z:RoomNode{roomId:$roomIdZ}), p=SHORTESTPATH((a)-[*..16]-(z)) RETURN p, LENGTH(p)")
// 多条最短路径
@Query("MATCH (a:RoomNode{roomId:$roomIdA}), (z:RoomNode{roomId:$roomIdZ}), p=ALLSHORTESTPATHS((a)-[*..16]-(z)) RETURN p, LENGTH(p)")
// 必经避让
@Query(
	"""
	MATCH (a:RoomNode{roomId:$roomIdA}), (z:RoomNode{roomId:$roomIdZ}), p=((a)-[*..16]-(z))
	WHERE
	ALL(m IN $mustIds WHERE m IN [v IN NODES(p) | v.roomId])
	AND
	NONE(v IN NODES(p) WHERE v.roomId IN $avoidIds)
	RETURN p,
	LENGTH(p)
	"""
)
// 必经避让排序数量
@Query(
	"""
	MATCH (a:RoomNode{roomId:$roomIdA}), (z:RoomNode{roomId:$roomIdZ}), p=((a)-[*..16]-(z))
	WHERE
	ALL(m IN $mustIds WHERE m IN [v IN NODES(p) | v.roomId])
	AND
	NONE(v IN NODES(p) WHERE v.roomId IN $avoidIds)
	RETURN p,
	LENGTH(p)
	ORDER BY LENGTH(p)
	LIMIT 4
	"""
)
// 必经避让排序数量:类型转换
@Query(
	"""
	MATCH (a:RoomNode{roomId:$roomIdA}), (z:RoomNode{roomId:$roomIdZ}), p=((a)-[*..16]-(z))
	WHERE
	ALL(m IN $mustIds WHERE m IN [v IN NODES(p) | v.roomId])
	AND
	NONE(v IN NODES(p) WHERE v.roomId IN $avoidIds)
	RETURN
	[v IN NODES(p) | v.roomId] AS roomIds,
	LENGTH(p) AS length
	ORDER BY LENGTH(p)
	LIMIT 4
	"""
)
// 必经避让排序数量:类型转换
@Query(
	"""
	MATCH (a:RoomNode{roomId:$roomIdA}), (z:RoomNode{roomId:$roomIdZ}), p=((a)-[*..16]-(z))
	WHERE
	ALL(m IN $mustIds WHERE m IN [v IN NODES(p) | v.roomId])
	AND
	NONE(v IN NODES(p) WHERE v.roomId IN $avoidIds)
	RETURN
	[r IN RELATIONSHIPS(p) | r.linkId] AS path,
	LENGTH(p) AS length
	ORDER BY LENGTH(p)
	LIMIT 4	
	"""
)
// 必经避让排序权重:类型转换
@Query(
	"""
	MATCH (a:RoomNode{roomId:$roomIdA}), (z:RoomNode{roomId:$roomIdZ}), p=((a)-[*..16]-(z))
	WHERE
	ALL(m IN $mustIds where m IN [v IN NODES(p) | v.roomId])
	AND
	NONE(v IN NODES(p) WHERE v.roomId IN $avoidIds)
	RETURN
	[r IN RELATIONSHIPS(p) | r.linkId] AS path,
	[r IN RELATIONSHIPS(p) | r.distance] AS v,
	REDUCE(distance = 0, r IN RELATIONSHIPS(p) | r.distance + distance) AS distance,
	LENGTH(p) AS length
	ORDER BY distance
	LIMIT 4
	"""
)

这里还有一个问题,就是返回多个值的时候,总是提示错误。
以前通过@QueryResult注解,但是新版没有这个注解了,暂时还没解决。