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
"""
)
// 无向图
match p = (n{portId:116600750})-[:NewPortRelationship*0..128]-(z:NewPortNode)
WHERE size(()-[:NewPortRelationship]-(z)) = 1
return p
// 无向图去重
match p = (i{portId:116600750})-[:NewPortRelationship*0..128]-(z:NewPortNode)
UNWIND NODES(p) AS n
WITH p, SIZE(COLLECT(DISTINCT n)) AS disNodeLength, length(p) + 1 AS nodeLength
WHERE disNodeLength = nodeLength
return p
这里还有一个问题,就是返回多个值的时候,总是提示错误。
以前通过@QueryResult
注解,但是新版没有这个注解了,暂时还没解决。