Skip to content

Commit

Permalink
Rewrite the IC-14 query
Browse files Browse the repository at this point in the history
  • Loading branch information
yixinglu committed Nov 24, 2022
1 parent 8503c01 commit 01df3e8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions nebula/queries/interactive-complex-14.ngql
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
MATCH p = allShortestPaths((person1)-[:KNOWS*..15]-(person2))
WHERE id(person1) == $person1 and id(person2) == $person2
WITH nodes(p) AS pathNodes
RETURN
WITH
[n IN pathNodes | id(n)] AS personIdsInPath,
reduce(weight=0.0, idx IN range(1,size(pathNodes)-1) | [prev IN [pathNodes[idx-1]] | [curr IN [pathNodes[idx]] | weight + size((curr)<-[:COMMENT_HAS_CREATOR]-(:`Comment`)-[:REPLY_OF_POST]->(:Post)-[:POST_HAS_CREATOR]->(prev))*1.0 + size((prev)<-[:COMMENT_HAS_CREATOR]-(:`Comment`)-[:REPLY_OF_POST]->(:Post)-[:POST_HAS_CREATOR]->(curr))*1.0 + size((prev)-[:COMMENT_HAS_CREATOR]-(:`Comment`)-[:REPLY_OF_COMMENT]-(:`Comment`)-[:COMMENT_HAS_CREATOR]-(curr))*0.5] ][0][0]) AS pathWight
ORDER BY pathWight DESC
[idx IN range(1, size(pathNodes)-1) | [prev IN [pathNodes[idx-1]] | [curr IN [pathNodes[idx]] | [prev, curr]]]] AS vertList
UNWIND vertList AS c
WITH c[0][0][0] AS prev, c[0][0][1] AS curr, personIdsInPath
MATCH (curr)<-[:COMMENT_HAS_CREATOR]-(:`Comment`)-[:REPLY_OF_POST]->(:Post)-[:POST_HAS_CREATOR]->(prev)
WITH count(*) AS cnt1, prev, curr, personIdsInPath
MATCH (prev)<-[:COMMENT_HAS_CREATOR]-(:`Comment`)-[:REPLY_OF_POST]->(:Post)-[:POST_HAS_CREATOR]->(curr)
WITH count(*) AS cnt2, cnt1, prev, curr, personIdsInPath
MATCH (prev)-[:COMMENT_HAS_CREATOR]-(:`Comment`)-[:REPLY_OF_COMMENT]-(:`Comment`)-[:COMMENT_HAS_CREATOR]-(curr)
WITH count(*) AS cnt3, cnt1, cnt2, personIdsInPath
WITH personIdsInPath, cnt1 + cnt2 + 0.5 * cnt3 AS weight
RETURN personIdsInPath, sum(weight) AS pathWeight
ORDER BY pathWeight DESC

0 comments on commit 01df3e8

Please sign in to comment.