diff --git a/nebula/queries-sf100/interactive-complex-12.ngql b/nebula/queries-sf100/interactive-complex-12.ngql index 7b8e271b5..b01bc9198 100644 --- a/nebula/queries-sf100/interactive-complex-12.ngql +++ b/nebula/queries-sf100/interactive-complex-12.ngql @@ -1,10 +1,10 @@ -MATCH (n:Person)-[:KNOWS]-(friend:Person)<-[:COMMENT_HAS_CREATOR]-(`comment`:`Comment`)-[:REPLY_OF_POST]->(:Post)-[:HAS_TAG]->(`tag`:`Tag`)-[:HAS_TYPE]->(tagClass:Tagclass)-[:IS_SUBCLASS_OF*0..100]->(baseTagClass:Tagclass) - WHERE id(n) == $personId AND (tagClass.Tagclass.name == $tagClassName OR baseTagClass.Tagclass.name == $tagClassName) - RETURN - toInteger(substr(id(friend),2)) AS personId, - friend.Person.firstName AS personFirstName, - friend.Person.lastName AS personLastName, - collect(DISTINCT `tag`.`Tag`.name) AS tagNames, - count(DISTINCT id(`comment`)) AS replyCount - ORDER BY replyCount DESC, personId ASC +MATCH (n:Person)-[:KNOWS]-(friend:Person)<-[:COMMENT_HAS_CREATOR]-(`comment`:`Comment`)-[:REPLY_OF_POST]->(:Post)-[:HAS_TAG]->(`tag`:`Tag`)-[:HAS_TYPE]->(tagClass:Tagclass)-[:IS_SUBCLASS_OF*0..100]->(baseTagClass:Tagclass) + WHERE id(n) == $personId AND (tagClass.Tagclass.name == $tagClassName OR baseTagClass.Tagclass.name == $tagClassName) + RETURN + toInteger(substr(id(friend),2)) AS personId, + friend.Person.firstName AS personFirstName, + friend.Person.lastName AS personLastName, + collect(DISTINCT `tag`.`Tag`.name) AS tagNames, + count(DISTINCT id(`comment`)) AS replyCount + ORDER BY replyCount DESC, personId ASC LIMIT 20 \ No newline at end of file diff --git a/nebula/queries-sf100/interactive-complex-2.ngql b/nebula/queries-sf100/interactive-complex-2.ngql index 997906e4c..049850b31 100644 --- a/nebula/queries-sf100/interactive-complex-2.ngql +++ b/nebula/queries-sf100/interactive-complex-2.ngql @@ -1,10 +1,10 @@ -GO FROM $personId OVER KNOWS BIDIRECT YIELD KNOWS._dst AS friendId -| GO FROM $-.friendId OVER POST_HAS_CREATOR_NEW, COMMENT_HAS_CREATOR_NEW REVERSELY WHERE (COMMENT_HAS_CREATOR_NEW.creationDate is not EMPTY and COMMENT_HAS_CREATOR_NEW.creationDate <= $maxDate) or (POST_HAS_CREATOR_NEW.creationDate is not EMPTY and POST_HAS_CREATOR_NEW.creationDate <= $maxDate) -YIELD - toInteger(substr($-.friendId, 2)) AS personId, - $^.Person.firstName AS personFirstName, - $^.Person.lastName AS personLastName, - toInteger(substr(id($$), 2)) AS messageId, - CASE WHEN COMMENT_HAS_CREATOR_NEW.content is not EMPTY THEN COMMENT_HAS_CREATOR_NEW.content ELSE CASE size(POST_HAS_CREATOR_NEW.imageFile) WHEN 0 THEN POST_HAS_CREATOR_NEW.content ELSE POST_HAS_CREATOR_NEW.imageFile END END AS messageContent, - CASE WHEN COMMENT_HAS_CREATOR_NEW.creationDate is not EMPTY THEN COMMENT_HAS_CREATOR_NEW.creationDate ELSE POST_HAS_CREATOR_NEW.creationDate END AS messageCreationDate +GO FROM $personId OVER KNOWS BIDIRECT YIELD KNOWS._dst AS friendId +| GO FROM $-.friendId OVER POST_HAS_CREATOR_NEW, COMMENT_HAS_CREATOR_NEW REVERSELY WHERE (COMMENT_HAS_CREATOR_NEW.creationDate is not EMPTY and COMMENT_HAS_CREATOR_NEW.creationDate <= $maxDate) or (POST_HAS_CREATOR_NEW.creationDate is not EMPTY and POST_HAS_CREATOR_NEW.creationDate <= $maxDate) +YIELD + toInteger(substr($-.friendId, 2)) AS personId, + $^.Person.firstName AS personFirstName, + $^.Person.lastName AS personLastName, + toInteger(substr(id($$), 2)) AS messageId, + CASE WHEN COMMENT_HAS_CREATOR_NEW.content is not EMPTY THEN COMMENT_HAS_CREATOR_NEW.content ELSE CASE size(POST_HAS_CREATOR_NEW.imageFile) WHEN 0 THEN POST_HAS_CREATOR_NEW.content ELSE POST_HAS_CREATOR_NEW.imageFile END END AS messageContent, + CASE WHEN COMMENT_HAS_CREATOR_NEW.creationDate is not EMPTY THEN COMMENT_HAS_CREATOR_NEW.creationDate ELSE POST_HAS_CREATOR_NEW.creationDate END AS messageCreationDate | ORDER BY $-.messageCreationDate DESC, $-.messageId ASC | LIMIT 20 \ No newline at end of file diff --git a/nebula/queries-sf100/interactive-complex-3.ngql b/nebula/queries-sf100/interactive-complex-3.ngql index 64e681cef..adba8394e 100644 --- a/nebula/queries-sf100/interactive-complex-3.ngql +++ b/nebula/queries-sf100/interactive-complex-3.ngql @@ -1,26 +1,26 @@ -MATCH (city:Place)-[:IS_PART_OF]->(country:Place) -WHERE country.Place.name == $countryXName OR country.Place.name == $countryYName -WITH collect(id(city)) AS cities -MATCH (person)-[:KNOWS*1..2]-(friend)-[:IS_LOCATED_IN]->(city) -WHERE id(person) == $personId AND id(friend) != $personId AND id(city) NOT IN cities -WITH DISTINCT friend -MATCH (friend)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message)-[:IS_LOCATED_IN]->(country) -WHERE - CASE - WHEN message.`Comment`.creationDate < $endDate AND message.`Comment`.creationDate >= $startDate AND (country.Place.name == $countryXName OR country.Place.name == $countryYName) THEN true - WHEN message.Post.creationDate < $endDate AND message.Post.creationDate >= $startDate AND (country.Place.name == $countryXName OR country.Place.name == $countryYName) THEN true - ELSE false - END -WITH friend, - CASE WHEN country.Place.name == $countryXName THEN 1 ELSE 0 END AS messageX, - CASE WHEN country.Place.name == $countryYName THEN 1 ELSE 0 END AS messageY -WITH friend, sum(messageX) AS xCount, sum(messageY) AS yCount -WHERE xCount>0 AND yCount>0 -RETURN tointeger(substr(id(friend), 2)) AS friendId, - friend.Person.firstName AS friendFirstName, - friend.Person.lastName AS friendLastName, - xCount, - yCount, - xCount + yCount AS xyCount - ORDER BY xyCount DESC, friendId ASC +MATCH (city:Place)-[:IS_PART_OF]->(country:Place) +WHERE country.Place.name == $countryXName OR country.Place.name == $countryYName +WITH collect(id(city)) AS cities +MATCH (person)-[:KNOWS*1..2]-(friend)-[:IS_LOCATED_IN]->(city) +WHERE id(person) == $personId AND id(friend) != $personId AND id(city) NOT IN cities +WITH DISTINCT friend +MATCH (friend)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message)-[:IS_LOCATED_IN]->(country) +WHERE + CASE + WHEN message.`Comment`.creationDate < $endDate AND message.`Comment`.creationDate >= $startDate AND (country.Place.name == $countryXName OR country.Place.name == $countryYName) THEN true + WHEN message.Post.creationDate < $endDate AND message.Post.creationDate >= $startDate AND (country.Place.name == $countryXName OR country.Place.name == $countryYName) THEN true + ELSE false + END +WITH friend, + CASE WHEN country.Place.name == $countryXName THEN 1 ELSE 0 END AS messageX, + CASE WHEN country.Place.name == $countryYName THEN 1 ELSE 0 END AS messageY +WITH friend, sum(messageX) AS xCount, sum(messageY) AS yCount +WHERE xCount>0 AND yCount>0 +RETURN tointeger(substr(id(friend), 2)) AS friendId, + friend.Person.firstName AS friendFirstName, + friend.Person.lastName AS friendLastName, + xCount, + yCount, + xCount + yCount AS xyCount + ORDER BY xyCount DESC, friendId ASC LIMIT 20 \ No newline at end of file diff --git a/nebula/queries-sf100/interactive-complex-4.ngql b/nebula/queries-sf100/interactive-complex-4.ngql index ace82c483..e02288387 100644 --- a/nebula/queries-sf100/interactive-complex-4.ngql +++ b/nebula/queries-sf100/interactive-complex-4.ngql @@ -1,12 +1,12 @@ -MATCH (person:Person)-[:KNOWS]-(:Person)<-[:POST_HAS_CREATOR]-(post:Post)-[:HAS_TAG]->(`tag`:`Tag`) - WHERE id(person) == $personId AND post.Post.creationDate >= $startDate AND post.Post.creationDate < $endDate - WITH person, count(post) AS postsOnTag, `tag` - OPTIONAL MATCH (person)-[:KNOWS]-()<-[:POST_HAS_CREATOR]-(oldPost:Post)-[:HAS_TAG]->(`tag`) - WHERE oldPost.Post.creationDate < $startDate - WITH person, postsOnTag, `tag`, count(oldPost) AS cp - WHERE cp == 0 - RETURN - `tag`.`Tag`.name AS tagName, - sum(postsOnTag) AS postCount - ORDER BY postCount DESC, tagName ASC +MATCH (person:Person)-[:KNOWS]-(:Person)<-[:POST_HAS_CREATOR]-(post:Post)-[:HAS_TAG]->(`tag`:`Tag`) + WHERE id(person) == $personId AND post.Post.creationDate >= $startDate AND post.Post.creationDate < $endDate + WITH person, count(post) AS postsOnTag, `tag` + OPTIONAL MATCH (person)-[:KNOWS]-()<-[:POST_HAS_CREATOR]-(oldPost:Post)-[:HAS_TAG]->(`tag`) + WHERE oldPost.Post.creationDate < $startDate + WITH person, postsOnTag, `tag`, count(oldPost) AS cp + WHERE cp == 0 + RETURN + `tag`.`Tag`.name AS tagName, + sum(postsOnTag) AS postCount + ORDER BY postCount DESC, tagName ASC limit 10 \ No newline at end of file diff --git a/nebula/queries-sf100/interactive-complex-7.ngql b/nebula/queries-sf100/interactive-complex-7.ngql index 883c34aff..bc8b5e530 100644 --- a/nebula/queries-sf100/interactive-complex-7.ngql +++ b/nebula/queries-sf100/interactive-complex-7.ngql @@ -1,32 +1,32 @@ -MATCH (person:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message)<-[like:LIKES_COMMENT|LIKES_POST]-(liker:Person) - WHERE id(person) == $personId -WITH - liker, - message, - like.creationDate AS likeTime, - person, - id(message) AS messageId -ORDER BY - likeTime DESC, - messageId ASC -WITH - liker, - head(collect({msg:message, likeTime:likeTime})) AS latestLike, - person -OPTIONAL MATCH p = (liker)-[:KNOWS]-(person) -RETURN - toInteger(substr(id(liker), 2)) AS personId, - liker.Person.firstName AS personFirstName, - liker.Person.lastName AS personLastName, - latestLike.likeTime AS likeCreationDate, - id(latestLike.msg) AS messageId, - CASE exists(latestLike.msg.content) - WHEN true THEN latestLike.msg.content - ELSE latestLike.msg.imageFile - END AS messageContent, - latestLike.msg.creationDate AS messageCreationDate, - p IS NULL AS isNew -ORDER BY - likeCreationDate DESC, - personId ASC +MATCH (person:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message)<-[like:LIKES_COMMENT|LIKES_POST]-(liker:Person) + WHERE id(person) == $personId +WITH + liker, + message, + like.creationDate AS likeTime, + person, + id(message) AS messageId +ORDER BY + likeTime DESC, + messageId ASC +WITH + liker, + head(collect({msg:message, likeTime:likeTime})) AS latestLike, + person +OPTIONAL MATCH p = (liker)-[:KNOWS]-(person) +RETURN + toInteger(substr(id(liker), 2)) AS personId, + liker.Person.firstName AS personFirstName, + liker.Person.lastName AS personLastName, + latestLike.likeTime AS likeCreationDate, + id(latestLike.msg) AS messageId, + CASE exists(latestLike.msg.content) + WHEN true THEN latestLike.msg.content + ELSE latestLike.msg.imageFile + END AS messageContent, + latestLike.msg.creationDate AS messageCreationDate, + p IS NULL AS isNew +ORDER BY + likeCreationDate DESC, + personId ASC LIMIT 20 \ No newline at end of file diff --git a/nebula/queries-sf100/interactive-complex-9.ngql b/nebula/queries-sf100/interactive-complex-9.ngql index 8668a8be4..f29aa0cb2 100644 --- a/nebula/queries-sf100/interactive-complex-9.ngql +++ b/nebula/queries-sf100/interactive-complex-9.ngql @@ -1,16 +1,16 @@ - GO 1 TO 2 STEPS FROM $personId OVER KNOWS BIDIRECT - WHERE KNOWS._dst != $personId - YIELD DISTINCT - KNOWS._dst AS personId, - $$.Person.firstName AS personFirstName, - $$.Person.lastName AS personLastName - | GO FROM $-.personId OVER POST_HAS_CREATOR_NEW, COMMENT_HAS_CREATOR_NEW REVERSELY - WHERE (COMMENT_HAS_CREATOR_NEW.creationDate is not EMPTY and COMMENT_HAS_CREATOR_NEW.creationDate < $maxDate) OR (POST_HAS_CREATOR_NEW.creationDate is not EMPTY and POST_HAS_CREATOR_NEW.creationDate < $maxDate) - YIELD - $-.personId AS personId, - $-.personFirstName AS personFirstName, - $-.personLastName AS personLastName, - toInteger(substr(id($$), 2)) AS messageId, - CASE WHEN COMMENT_HAS_CREATOR_NEW.content is not EMPTY THEN COMMENT_HAS_CREATOR_NEW.content ELSE CASE size(POST_HAS_CREATOR_NEW.imageFile) WHEN 0 THEN POST_HAS_CREATOR_NEW.content ELSE POST_HAS_CREATOR_NEW.imageFile END END AS messageContent, - CASE WHEN COMMENT_HAS_CREATOR_NEW.creationDate is not EMPTY THEN COMMENT_HAS_CREATOR_NEW.creationDate ELSE POST_HAS_CREATOR_NEW.creationDate END AS messageCreationDate - | ORDER BY $-.messageCreationDate DESC, $-.messageId ASC | LIMIT 20 + GO 1 TO 2 STEPS FROM $personId OVER KNOWS BIDIRECT + WHERE KNOWS._dst != $personId + YIELD DISTINCT + KNOWS._dst AS personId, + $$.Person.firstName AS personFirstName, + $$.Person.lastName AS personLastName + | GO FROM $-.personId OVER POST_HAS_CREATOR_NEW, COMMENT_HAS_CREATOR_NEW REVERSELY + WHERE (COMMENT_HAS_CREATOR_NEW.creationDate is not EMPTY and COMMENT_HAS_CREATOR_NEW.creationDate < $maxDate) OR (POST_HAS_CREATOR_NEW.creationDate is not EMPTY and POST_HAS_CREATOR_NEW.creationDate < $maxDate) + YIELD + $-.personId AS personId, + $-.personFirstName AS personFirstName, + $-.personLastName AS personLastName, + toInteger(substr(id($$), 2)) AS messageId, + CASE WHEN COMMENT_HAS_CREATOR_NEW.content is not EMPTY THEN COMMENT_HAS_CREATOR_NEW.content ELSE CASE size(POST_HAS_CREATOR_NEW.imageFile) WHEN 0 THEN POST_HAS_CREATOR_NEW.content ELSE POST_HAS_CREATOR_NEW.imageFile END END AS messageContent, + CASE WHEN COMMENT_HAS_CREATOR_NEW.creationDate is not EMPTY THEN COMMENT_HAS_CREATOR_NEW.creationDate ELSE POST_HAS_CREATOR_NEW.creationDate END AS messageCreationDate + | ORDER BY $-.messageCreationDate DESC, $-.messageId ASC | LIMIT 20 diff --git a/nebula/queries-sf100/interactive-short-2.ngql b/nebula/queries-sf100/interactive-short-2.ngql index a955d6dbd..3641aea96 100644 --- a/nebula/queries-sf100/interactive-short-2.ngql +++ b/nebula/queries-sf100/interactive-short-2.ngql @@ -1,19 +1,19 @@ -MATCH (n:Person)<-[:COMMENT_HAS_CREATOR | POST_HAS_CREATOR]-(message)-[:REPLY_OF_POST | REPLY_OF_COMMENT*0..100]->(p:Post) - WHERE id(n)==$personId -MATCH (p)-[:POST_HAS_CREATOR]->(c) - RETURN - id(message) as messageId, - CASE tags(message)[0] - WHEN "Comment" THEN message.`Comment`.content - ELSE CASE size(message.Post.imageFile) WHEN 0 THEN message.Post.content ELSE message.Post.imageFile END - END AS messageContent, - CASE tags(message)[0] - WHEN "Comment" THEN message.`Comment`.creationDate - ELSE message.Post.creationDate - END AS messageCreationDate, - id(p) AS originalPostId, - id(c) AS originalPostAuthorId, - c.Person.firstName as originalPostAuthorFirstName, - c.Person.lastName as originalPostAuthorLastName - ORDER BY messageCreationDate DESC +MATCH (n:Person)<-[:COMMENT_HAS_CREATOR | POST_HAS_CREATOR]-(message)-[:REPLY_OF_POST | REPLY_OF_COMMENT*0..100]->(p:Post) + WHERE id(n)==$personId +MATCH (p)-[:POST_HAS_CREATOR]->(c) + RETURN + id(message) as messageId, + CASE tags(message)[0] + WHEN "Comment" THEN message.`Comment`.content + ELSE CASE size(message.Post.imageFile) WHEN 0 THEN message.Post.content ELSE message.Post.imageFile END + END AS messageContent, + CASE tags(message)[0] + WHEN "Comment" THEN message.`Comment`.creationDate + ELSE message.Post.creationDate + END AS messageCreationDate, + id(p) AS originalPostId, + id(c) AS originalPostAuthorId, + c.Person.firstName as originalPostAuthorFirstName, + c.Person.lastName as originalPostAuthorLastName + ORDER BY messageCreationDate DESC LIMIT 10 \ No newline at end of file diff --git a/nebula/queries-sf100/interactive-short-6.ngql b/nebula/queries-sf100/interactive-short-6.ngql index a46364909..f39d43060 100644 --- a/nebula/queries-sf100/interactive-short-6.ngql +++ b/nebula/queries-sf100/interactive-short-6.ngql @@ -1,8 +1,8 @@ -MATCH (m)-[:REPLY_OF_COMMENT | REPLY_OF_POST *0..100]->(p:Post)<-[:CONTAINER_OF]-(f:Forum)-[:HAS_MODERATOR]->(mod:Person) - WHERE id(m) == $commentId OR id(m) == $postId - RETURN - id(f) AS forumId, - f.Forum.title AS forumTitle, - id(mod) AS moderatorId, - mod.Person.firstName AS moderatorFirstName, +MATCH (m)-[:REPLY_OF_COMMENT | REPLY_OF_POST *0..100]->(p:Post)<-[:CONTAINER_OF]-(f:Forum)-[:HAS_MODERATOR]->(mod:Person) + WHERE id(m) == $commentId OR id(m) == $postId + RETURN + id(f) AS forumId, + f.Forum.title AS forumTitle, + id(mod) AS moderatorId, + mod.Person.firstName AS moderatorFirstName, mod.Person.lastName AS moderatorLastName \ No newline at end of file diff --git a/nebula/queries-sf100/interactive-short-7.ngql b/nebula/queries-sf100/interactive-short-7.ngql index be864b311..16a50df13 100644 --- a/nebula/queries-sf100/interactive-short-7.ngql +++ b/nebula/queries-sf100/interactive-short-7.ngql @@ -1,15 +1,15 @@ -MATCH (m)<-[:REPLY_OF_COMMENT|REPLY_OF_POST]-(c:`Comment`)-[:COMMENT_HAS_CREATOR]->(p:Person) - WHERE id(m) == $commentId OR id(m) == $postId - OPTIONAL MATCH (m)-[:COMMENT_HAS_CREATOR|POST_HAS_CREATOR]->(a:Person)-[r:KNOWS]-(p) - RETURN - id(c) AS commentId, - c.`Comment`.content AS commentContent, - c.`Comment`.creationDate AS commentCreationDate, - toInteger(substr(id(p), 2)) AS replyAuthorId, - p.Person.firstName AS replyAuthorFirstName, - p.Person.lastName AS replyAuthorLastName, - CASE dst(r) - WHEN null THEN false - ELSE true - END AS replyAuthorKnowsOriginalMessageAuthor +MATCH (m)<-[:REPLY_OF_COMMENT|REPLY_OF_POST]-(c:`Comment`)-[:COMMENT_HAS_CREATOR]->(p:Person) + WHERE id(m) == $commentId OR id(m) == $postId + OPTIONAL MATCH (m)-[:COMMENT_HAS_CREATOR|POST_HAS_CREATOR]->(a:Person)-[r:KNOWS]-(p) + RETURN + id(c) AS commentId, + c.`Comment`.content AS commentContent, + c.`Comment`.creationDate AS commentCreationDate, + toInteger(substr(id(p), 2)) AS replyAuthorId, + p.Person.firstName AS replyAuthorFirstName, + p.Person.lastName AS replyAuthorLastName, + CASE dst(r) + WHEN null THEN false + ELSE true + END AS replyAuthorKnowsOriginalMessageAuthor ORDER BY commentCreationDate DESC, replyAuthorId \ No newline at end of file diff --git a/nebula/queries/interactive-complex-12.ngql b/nebula/queries/interactive-complex-12.ngql index 9f59e7fbf..14608656a 100644 --- a/nebula/queries/interactive-complex-12.ngql +++ b/nebula/queries/interactive-complex-12.ngql @@ -1,15 +1,15 @@ -MATCH (tag1:`Tag`)-[:HAS_TYPE|IS_SUBCLASS_OF*0..6]->(baseTagClass:Tagclass) -WHERE tag1.`Tag`.name == $tagClassName OR baseTagClass.Tagclass.name == $tagClassName -WITH collect(id(tag1)) as T -MATCH (p:Person)-[:KNOWS]-(friend:Person)<-[:COMMENT_HAS_CREATOR]-(comment1:`Comment`)-[:REPLY_OF_POST]->(:Post)-[:HAS_TAG]->(tag2:`Tag`) -WHERE id(p) == $personId AND id(tag2) in T -RETURN - toInteger(substr(id(friend),2)) AS personId, - friend.Person.firstName AS personFirstName, - friend.Person.lastName AS personLastName, - collect(DISTINCT tag2.`Tag`.name) AS tagNames, - count(DISTINCT id(comment1)) AS replyCount -ORDER BY - replyCount DESC, - personId ASC +MATCH (tag1:`Tag`)-[:HAS_TYPE|IS_SUBCLASS_OF*0..6]->(baseTagClass:Tagclass) +WHERE tag1.`Tag`.name == $tagClassName OR baseTagClass.Tagclass.name == $tagClassName +WITH collect(id(tag1)) as T +MATCH (p:Person)-[:KNOWS]-(friend:Person)<-[:COMMENT_HAS_CREATOR]-(comment1:`Comment`)-[:REPLY_OF_POST]->(:Post)-[:HAS_TAG]->(tag2:`Tag`) +WHERE id(p) == $personId AND id(tag2) in T +RETURN + toInteger(substr(id(friend),2)) AS personId, + friend.Person.firstName AS personFirstName, + friend.Person.lastName AS personLastName, + collect(DISTINCT tag2.`Tag`.name) AS tagNames, + count(DISTINCT id(comment1)) AS replyCount +ORDER BY + replyCount DESC, + personId ASC LIMIT 20 \ No newline at end of file diff --git a/nebula/queries/interactive-complex-2.ngql b/nebula/queries/interactive-complex-2.ngql index f6f5a7a37..881f65bb9 100644 --- a/nebula/queries/interactive-complex-2.ngql +++ b/nebula/queries/interactive-complex-2.ngql @@ -1,10 +1,10 @@ -GO FROM $personId OVER KNOWS BIDIRECT YIELD KNOWS._dst AS friendId -| GO FROM $-.friendId OVER POST_HAS_CREATOR, COMMENT_HAS_CREATOR REVERSELY WHERE (COMMENT_HAS_CREATOR.creationDate is not EMPTY and COMMENT_HAS_CREATOR.creationDate <= $maxDate) or (POST_HAS_CREATOR.creationDate is not EMPTY and POST_HAS_CREATOR.creationDate <= $maxDate) -YIELD - toInteger(substr($-.friendId, 2)) AS personId, - $^.Person.firstName AS personFirstName, - $^.Person.lastName AS personLastName, - toInteger(substr(id($$), 2)) AS messageId, - CASE WHEN COMMENT_HAS_CREATOR.content is not EMPTY THEN COMMENT_HAS_CREATOR.content ELSE CASE size(POST_HAS_CREATOR.imageFile) WHEN 0 THEN POST_HAS_CREATOR.content ELSE POST_HAS_CREATOR.imageFile END END AS messageContent, - CASE WHEN COMMENT_HAS_CREATOR.creationDate is not EMPTY THEN COMMENT_HAS_CREATOR.creationDate ELSE POST_HAS_CREATOR.creationDate END AS messageCreationDate +GO FROM $personId OVER KNOWS BIDIRECT YIELD KNOWS._dst AS friendId +| GO FROM $-.friendId OVER POST_HAS_CREATOR, COMMENT_HAS_CREATOR REVERSELY WHERE (COMMENT_HAS_CREATOR.creationDate is not EMPTY and COMMENT_HAS_CREATOR.creationDate <= $maxDate) or (POST_HAS_CREATOR.creationDate is not EMPTY and POST_HAS_CREATOR.creationDate <= $maxDate) +YIELD + toInteger(substr($-.friendId, 2)) AS personId, + $^.Person.firstName AS personFirstName, + $^.Person.lastName AS personLastName, + toInteger(substr(id($$), 2)) AS messageId, + CASE WHEN COMMENT_HAS_CREATOR.content is not EMPTY THEN COMMENT_HAS_CREATOR.content ELSE CASE size(POST_HAS_CREATOR.imageFile) WHEN 0 THEN POST_HAS_CREATOR.content ELSE POST_HAS_CREATOR.imageFile END END AS messageContent, + CASE WHEN COMMENT_HAS_CREATOR.creationDate is not EMPTY THEN COMMENT_HAS_CREATOR.creationDate ELSE POST_HAS_CREATOR.creationDate END AS messageCreationDate | ORDER BY $-.messageCreationDate DESC, $-.messageId ASC | LIMIT 20 \ No newline at end of file diff --git a/nebula/queries/interactive-complex-3.ngql b/nebula/queries/interactive-complex-3.ngql index b657995db..a80570302 100644 --- a/nebula/queries/interactive-complex-3.ngql +++ b/nebula/queries/interactive-complex-3.ngql @@ -1,18 +1,18 @@ -MATCH (person)-[:KNOWS*1..2]-(friend)-[:IS_LOCATED_IN]->(:Place)-[:IS_PART_OF]->(country:Place) -WHERE id(person) == $personId AND id(friend) != $personId AND country.Place.name != $countryXName AND country.Place.name != $countryYName -WITH DISTINCT friend -MATCH (friend)<-[m:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-()-[:IS_LOCATED_IN]->(country) -WHERE m.creationDate <= $startDate+Duration({days:$durationDays}) AND m.creationDate >= $startDate AND country.Place.name IN [$countryXName, $countryYName] -WITH friend, - CASE WHEN country.Place.name == $countryXName THEN 1 ELSE 0 END AS messageX, - CASE WHEN country.Place.name == $countryYName THEN 1 ELSE 0 END AS messageY -WITH friend, sum(messageX) AS xCount, sum(messageY) AS yCount -WHERE xCount>0 AND yCount>0 -RETURN tointeger(substr(id(friend), 2)) AS friendId, - friend.Person.firstName AS friendFirstName, - friend.Person.lastName AS friendLastName, - xCount, - yCount, - xCount + yCount AS xyCount -ORDER BY xyCount DESC, friendId ASC -LIMIT 20 +MATCH (person)-[:KNOWS*1..2]-(friend)-[:IS_LOCATED_IN]->(:Place)-[:IS_PART_OF]->(country:Place) +WHERE id(person) == $personId AND id(friend) != $personId AND country.Place.name != $countryXName AND country.Place.name != $countryYName +WITH DISTINCT friend +MATCH (friend)<-[m:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-()-[:IS_LOCATED_IN]->(country) +WHERE m.creationDate <= $startDate+Duration({days:$durationDays}) AND m.creationDate >= $startDate AND country.Place.name IN [$countryXName, $countryYName] +WITH friend, + CASE WHEN country.Place.name == $countryXName THEN 1 ELSE 0 END AS messageX, + CASE WHEN country.Place.name == $countryYName THEN 1 ELSE 0 END AS messageY +WITH friend, sum(messageX) AS xCount, sum(messageY) AS yCount +WHERE xCount>0 AND yCount>0 +RETURN tointeger(substr(id(friend), 2)) AS friendId, + friend.Person.firstName AS friendFirstName, + friend.Person.lastName AS friendLastName, + xCount, + yCount, + xCount + yCount AS xyCount +ORDER BY xyCount DESC, friendId ASC +LIMIT 20 diff --git a/nebula/queries/interactive-complex-4.ngql b/nebula/queries/interactive-complex-4.ngql index ace82c483..e02288387 100644 --- a/nebula/queries/interactive-complex-4.ngql +++ b/nebula/queries/interactive-complex-4.ngql @@ -1,12 +1,12 @@ -MATCH (person:Person)-[:KNOWS]-(:Person)<-[:POST_HAS_CREATOR]-(post:Post)-[:HAS_TAG]->(`tag`:`Tag`) - WHERE id(person) == $personId AND post.Post.creationDate >= $startDate AND post.Post.creationDate < $endDate - WITH person, count(post) AS postsOnTag, `tag` - OPTIONAL MATCH (person)-[:KNOWS]-()<-[:POST_HAS_CREATOR]-(oldPost:Post)-[:HAS_TAG]->(`tag`) - WHERE oldPost.Post.creationDate < $startDate - WITH person, postsOnTag, `tag`, count(oldPost) AS cp - WHERE cp == 0 - RETURN - `tag`.`Tag`.name AS tagName, - sum(postsOnTag) AS postCount - ORDER BY postCount DESC, tagName ASC +MATCH (person:Person)-[:KNOWS]-(:Person)<-[:POST_HAS_CREATOR]-(post:Post)-[:HAS_TAG]->(`tag`:`Tag`) + WHERE id(person) == $personId AND post.Post.creationDate >= $startDate AND post.Post.creationDate < $endDate + WITH person, count(post) AS postsOnTag, `tag` + OPTIONAL MATCH (person)-[:KNOWS]-()<-[:POST_HAS_CREATOR]-(oldPost:Post)-[:HAS_TAG]->(`tag`) + WHERE oldPost.Post.creationDate < $startDate + WITH person, postsOnTag, `tag`, count(oldPost) AS cp + WHERE cp == 0 + RETURN + `tag`.`Tag`.name AS tagName, + sum(postsOnTag) AS postCount + ORDER BY postCount DESC, tagName ASC limit 10 \ No newline at end of file diff --git a/nebula/queries/interactive-complex-7.ngql b/nebula/queries/interactive-complex-7.ngql index 7aa188409..0fc5ee630 100644 --- a/nebula/queries/interactive-complex-7.ngql +++ b/nebula/queries/interactive-complex-7.ngql @@ -1,34 +1,34 @@ -MATCH (person:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message)<-[like:LIKES_COMMENT|LIKES_POST]-(liker:Person) - WHERE id(person) == $personId -WITH - liker, - message, - like.creationDate AS likeTime, - person, - id(message) AS messageId -ORDER BY - likeTime DESC, - messageId ASC -WITH - liker, - head(collect({msg:message, likeTime:likeTime})) AS latestLike, - person -OPTIONAL MATCH (liker)-[e:KNOWS]-(person) -RETURN - toInteger(substr(id(liker), 2)) AS personId, - liker.Person.firstName AS personFirstName, - liker.Person.lastName AS personLastName, - latestLike.likeTime AS likeCreationDate, - id(latestLike.msg) AS messageId, - CASE WHEN tags(latestLike.msg) == ["Post"] THEN - CASE WHEN size(latestLike.msg.imageFile) == 0 THEN latestLike.msg.content - ELSE latestLike.msg.imageFile - END - ELSE latestLike.msg.content - END AS messageContent, - latestLike.msg.creationDate AS messageCreationDate, - e IS NULL AS isNew -ORDER BY - likeCreationDate DESC, - personId ASC +MATCH (person:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message)<-[like:LIKES_COMMENT|LIKES_POST]-(liker:Person) + WHERE id(person) == $personId +WITH + liker, + message, + like.creationDate AS likeTime, + person, + id(message) AS messageId +ORDER BY + likeTime DESC, + messageId ASC +WITH + liker, + head(collect({msg:message, likeTime:likeTime})) AS latestLike, + person +OPTIONAL MATCH (liker)-[e:KNOWS]-(person) +RETURN + toInteger(substr(id(liker), 2)) AS personId, + liker.Person.firstName AS personFirstName, + liker.Person.lastName AS personLastName, + latestLike.likeTime AS likeCreationDate, + id(latestLike.msg) AS messageId, + CASE WHEN tags(latestLike.msg) == ["Post"] THEN + CASE WHEN size(latestLike.msg.imageFile) == 0 THEN latestLike.msg.content + ELSE latestLike.msg.imageFile + END + ELSE latestLike.msg.content + END AS messageContent, + latestLike.msg.creationDate AS messageCreationDate, + e IS NULL AS isNew +ORDER BY + likeCreationDate DESC, + personId ASC LIMIT 20 \ No newline at end of file diff --git a/nebula/queries/interactive-complex-9.ngql b/nebula/queries/interactive-complex-9.ngql index 3e7216e75..d77ea0d95 100644 --- a/nebula/queries/interactive-complex-9.ngql +++ b/nebula/queries/interactive-complex-9.ngql @@ -1,16 +1,16 @@ - GO 1 TO 2 STEPS FROM $personId OVER KNOWS BIDIRECT - WHERE KNOWS._dst != $personId - YIELD DISTINCT - KNOWS._dst AS personId, - $$.Person.firstName AS personFirstName, - $$.Person.lastName AS personLastName - | GO FROM $-.personId OVER POST_HAS_CREATOR, COMMENT_HAS_CREATOR REVERSELY - WHERE (COMMENT_HAS_CREATOR.creationDate is not EMPTY and COMMENT_HAS_CREATOR.creationDate < $maxDate) OR (POST_HAS_CREATOR.creationDate is not EMPTY and POST_HAS_CREATOR.creationDate < $maxDate) - YIELD - $-.personId AS personId, - $-.personFirstName AS personFirstName, - $-.personLastName AS personLastName, - toInteger(substr(id($$), 2)) AS messageId, - CASE WHEN COMMENT_HAS_CREATOR.content is not EMPTY THEN COMMENT_HAS_CREATOR.content ELSE CASE size(POST_HAS_CREATOR.imageFile) WHEN 0 THEN POST_HAS_CREATOR.content ELSE POST_HAS_CREATOR.imageFile END END AS messageContent, - CASE WHEN COMMENT_HAS_CREATOR.creationDate is not EMPTY THEN COMMENT_HAS_CREATOR.creationDate ELSE POST_HAS_CREATOR.creationDate END AS messageCreationDate - | ORDER BY $-.messageCreationDate DESC, $-.messageId ASC | LIMIT 20 + GO 1 TO 2 STEPS FROM $personId OVER KNOWS BIDIRECT + WHERE KNOWS._dst != $personId + YIELD DISTINCT + KNOWS._dst AS personId, + $$.Person.firstName AS personFirstName, + $$.Person.lastName AS personLastName + | GO FROM $-.personId OVER POST_HAS_CREATOR, COMMENT_HAS_CREATOR REVERSELY + WHERE (COMMENT_HAS_CREATOR.creationDate is not EMPTY and COMMENT_HAS_CREATOR.creationDate < $maxDate) OR (POST_HAS_CREATOR.creationDate is not EMPTY and POST_HAS_CREATOR.creationDate < $maxDate) + YIELD + $-.personId AS personId, + $-.personFirstName AS personFirstName, + $-.personLastName AS personLastName, + toInteger(substr(id($$), 2)) AS messageId, + CASE WHEN COMMENT_HAS_CREATOR.content is not EMPTY THEN COMMENT_HAS_CREATOR.content ELSE CASE size(POST_HAS_CREATOR.imageFile) WHEN 0 THEN POST_HAS_CREATOR.content ELSE POST_HAS_CREATOR.imageFile END END AS messageContent, + CASE WHEN COMMENT_HAS_CREATOR.creationDate is not EMPTY THEN COMMENT_HAS_CREATOR.creationDate ELSE POST_HAS_CREATOR.creationDate END AS messageCreationDate + | ORDER BY $-.messageCreationDate DESC, $-.messageId ASC | LIMIT 20 diff --git a/nebula/queries/interactive-short-2.ngql b/nebula/queries/interactive-short-2.ngql index a955d6dbd..3641aea96 100644 --- a/nebula/queries/interactive-short-2.ngql +++ b/nebula/queries/interactive-short-2.ngql @@ -1,19 +1,19 @@ -MATCH (n:Person)<-[:COMMENT_HAS_CREATOR | POST_HAS_CREATOR]-(message)-[:REPLY_OF_POST | REPLY_OF_COMMENT*0..100]->(p:Post) - WHERE id(n)==$personId -MATCH (p)-[:POST_HAS_CREATOR]->(c) - RETURN - id(message) as messageId, - CASE tags(message)[0] - WHEN "Comment" THEN message.`Comment`.content - ELSE CASE size(message.Post.imageFile) WHEN 0 THEN message.Post.content ELSE message.Post.imageFile END - END AS messageContent, - CASE tags(message)[0] - WHEN "Comment" THEN message.`Comment`.creationDate - ELSE message.Post.creationDate - END AS messageCreationDate, - id(p) AS originalPostId, - id(c) AS originalPostAuthorId, - c.Person.firstName as originalPostAuthorFirstName, - c.Person.lastName as originalPostAuthorLastName - ORDER BY messageCreationDate DESC +MATCH (n:Person)<-[:COMMENT_HAS_CREATOR | POST_HAS_CREATOR]-(message)-[:REPLY_OF_POST | REPLY_OF_COMMENT*0..100]->(p:Post) + WHERE id(n)==$personId +MATCH (p)-[:POST_HAS_CREATOR]->(c) + RETURN + id(message) as messageId, + CASE tags(message)[0] + WHEN "Comment" THEN message.`Comment`.content + ELSE CASE size(message.Post.imageFile) WHEN 0 THEN message.Post.content ELSE message.Post.imageFile END + END AS messageContent, + CASE tags(message)[0] + WHEN "Comment" THEN message.`Comment`.creationDate + ELSE message.Post.creationDate + END AS messageCreationDate, + id(p) AS originalPostId, + id(c) AS originalPostAuthorId, + c.Person.firstName as originalPostAuthorFirstName, + c.Person.lastName as originalPostAuthorLastName + ORDER BY messageCreationDate DESC LIMIT 10 \ No newline at end of file diff --git a/nebula/queries/interactive-short-6.ngql b/nebula/queries/interactive-short-6.ngql index a46364909..f39d43060 100644 --- a/nebula/queries/interactive-short-6.ngql +++ b/nebula/queries/interactive-short-6.ngql @@ -1,8 +1,8 @@ -MATCH (m)-[:REPLY_OF_COMMENT | REPLY_OF_POST *0..100]->(p:Post)<-[:CONTAINER_OF]-(f:Forum)-[:HAS_MODERATOR]->(mod:Person) - WHERE id(m) == $commentId OR id(m) == $postId - RETURN - id(f) AS forumId, - f.Forum.title AS forumTitle, - id(mod) AS moderatorId, - mod.Person.firstName AS moderatorFirstName, +MATCH (m)-[:REPLY_OF_COMMENT | REPLY_OF_POST *0..100]->(p:Post)<-[:CONTAINER_OF]-(f:Forum)-[:HAS_MODERATOR]->(mod:Person) + WHERE id(m) == $commentId OR id(m) == $postId + RETURN + id(f) AS forumId, + f.Forum.title AS forumTitle, + id(mod) AS moderatorId, + mod.Person.firstName AS moderatorFirstName, mod.Person.lastName AS moderatorLastName \ No newline at end of file diff --git a/nebula/queries/interactive-short-7.ngql b/nebula/queries/interactive-short-7.ngql index be864b311..16a50df13 100644 --- a/nebula/queries/interactive-short-7.ngql +++ b/nebula/queries/interactive-short-7.ngql @@ -1,15 +1,15 @@ -MATCH (m)<-[:REPLY_OF_COMMENT|REPLY_OF_POST]-(c:`Comment`)-[:COMMENT_HAS_CREATOR]->(p:Person) - WHERE id(m) == $commentId OR id(m) == $postId - OPTIONAL MATCH (m)-[:COMMENT_HAS_CREATOR|POST_HAS_CREATOR]->(a:Person)-[r:KNOWS]-(p) - RETURN - id(c) AS commentId, - c.`Comment`.content AS commentContent, - c.`Comment`.creationDate AS commentCreationDate, - toInteger(substr(id(p), 2)) AS replyAuthorId, - p.Person.firstName AS replyAuthorFirstName, - p.Person.lastName AS replyAuthorLastName, - CASE dst(r) - WHEN null THEN false - ELSE true - END AS replyAuthorKnowsOriginalMessageAuthor +MATCH (m)<-[:REPLY_OF_COMMENT|REPLY_OF_POST]-(c:`Comment`)-[:COMMENT_HAS_CREATOR]->(p:Person) + WHERE id(m) == $commentId OR id(m) == $postId + OPTIONAL MATCH (m)-[:COMMENT_HAS_CREATOR|POST_HAS_CREATOR]->(a:Person)-[r:KNOWS]-(p) + RETURN + id(c) AS commentId, + c.`Comment`.content AS commentContent, + c.`Comment`.creationDate AS commentCreationDate, + toInteger(substr(id(p), 2)) AS replyAuthorId, + p.Person.firstName AS replyAuthorFirstName, + p.Person.lastName AS replyAuthorLastName, + CASE dst(r) + WHEN null THEN false + ELSE true + END AS replyAuthorKnowsOriginalMessageAuthor ORDER BY commentCreationDate DESC, replyAuthorId \ No newline at end of file diff --git a/nebula/queries2/interactive-complex-11.ngql b/nebula/queries2/interactive-complex-11.ngql index c4e9dfe04..e5c78f2c3 100644 --- a/nebula/queries2/interactive-complex-11.ngql +++ b/nebula/queries2/interactive-complex-11.ngql @@ -1,13 +1,13 @@ -MATCH (person:Person)-[:KNOWS*1..2]-(friend:Person) - WHERE id(person) == $personId AND not(id(person)==id(friend)) - WITH DISTINCT friend -MATCH (friend)-[workAt:WORK_AT]->(company:Organisation)-[:IS_LOCATED_IN]->(:Place {name:$countryName}) - WHERE workAt.workFrom < $workFromYear - RETURN - id(friend) AS personId, - friend.Person.firstName AS personFirstName, - friend.Person.lastName AS personLastName, - company.Organisation.name AS organizationName, - workAt.workFrom AS organizationWorkFromYear - ORDER BY organizationWorkFromYear ASC, personId ASC, organizationName DESC +MATCH (person:Person)-[:KNOWS*1..2]-(friend:Person) + WHERE id(person) == $personId AND not(id(person)==id(friend)) + WITH DISTINCT friend +MATCH (friend)-[workAt:WORK_AT]->(company:Organisation)-[:IS_LOCATED_IN]->(:Place {name:$countryName}) + WHERE workAt.workFrom < $workFromYear + RETURN + id(friend) AS personId, + friend.Person.firstName AS personFirstName, + friend.Person.lastName AS personLastName, + company.Organisation.name AS organizationName, + workAt.workFrom AS organizationWorkFromYear + ORDER BY organizationWorkFromYear ASC, personId ASC, organizationName DESC LIMIT 10 \ No newline at end of file diff --git a/nebula/queries2/interactive-complex-12.ngql b/nebula/queries2/interactive-complex-12.ngql index b498e0ac7..37c960a63 100644 --- a/nebula/queries2/interactive-complex-12.ngql +++ b/nebula/queries2/interactive-complex-12.ngql @@ -1,11 +1,11 @@ -MATCH (n:Person)-[:KNOWS]-(friend:Person)<-[:COMMENT_HAS_CREATOR]-(`comment`:`Comment`)-[:REPLY_OF_POST]->(:Post)-[:HAS_TAG]->(`tag`:`Tag`)-[:HAS_TYPE]->(tagClass:Tagclass)-[:IS_SUBCLASS_OF*0..100]->(baseTagClass:Tagclass) - WHERE id(n) == $personId AND (tagClass.Tagclass.name == $tagClassName OR baseTagClass.Tagclass.name == $tagClassName) - RETURN - /* id(friend) AS personId, 属性裁剪待改进, 暂时通过以下写法规避问题*/ - true ? id(friend) : id(n)+id(tagClass)+id(baseTagClass) AS personId, - friend.Person.firstName AS personFirstName, - friend.Person.lastName AS personLastName, - collect(DISTINCT `tag`.`Tag`.name) AS tagNames, - count(DISTINCT id(`comment`)) AS replyCount - ORDER BY replyCount DESC, personId ASC - LIMIT 20 +MATCH (n:Person)-[:KNOWS]-(friend:Person)<-[:COMMENT_HAS_CREATOR]-(`comment`:`Comment`)-[:REPLY_OF_POST]->(:Post)-[:HAS_TAG]->(`tag`:`Tag`)-[:HAS_TYPE]->(tagClass:Tagclass)-[:IS_SUBCLASS_OF*0..100]->(baseTagClass:Tagclass) + WHERE id(n) == $personId AND (tagClass.Tagclass.name == $tagClassName OR baseTagClass.Tagclass.name == $tagClassName) + RETURN + /* id(friend) AS personId, 属性裁剪待改进, 暂时通过以下写法规避问题*/ + true ? id(friend) : id(n)+id(tagClass)+id(baseTagClass) AS personId, + friend.Person.firstName AS personFirstName, + friend.Person.lastName AS personLastName, + collect(DISTINCT `tag`.`Tag`.name) AS tagNames, + count(DISTINCT id(`comment`)) AS replyCount + ORDER BY replyCount DESC, personId ASC + LIMIT 20 diff --git a/nebula/queries2/interactive-complex-2.ngql b/nebula/queries2/interactive-complex-2.ngql index e76c68aff..7b5552c1e 100644 --- a/nebula/queries2/interactive-complex-2.ngql +++ b/nebula/queries2/interactive-complex-2.ngql @@ -1,17 +1,17 @@ -MATCH (n:Person)-[:KNOWS]-(friend:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message) - WHERE id(n) == $personId and (message.`Comment`.creationDate <= $maxDate or message.`Post`.creationDate <= $maxDate) - RETURN - id(friend) AS personId, - friend.Person.firstName AS personFirstName, - friend.Person.lastName AS personLastName, - id(message) AS messageId, - CASE exists(message.`Comment`.content) - WHEN true THEN coalesce(message.`Comment`.imageFile,message.`Comment`.content) - ELSE coalesce(message.Post.imageFile,message.Post.content) - END AS messageContent, - CASE exists(message.`Comment`.content) - WHEN true THEN message.`Comment`.creationDate - ELSE message.Post.creationDate - END AS messageCreationDate - ORDER BY messageCreationDate DESC, messageId ASC - LIMIT 20 +MATCH (n:Person)-[:KNOWS]-(friend:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message) + WHERE id(n) == $personId and (message.`Comment`.creationDate <= $maxDate or message.`Post`.creationDate <= $maxDate) + RETURN + id(friend) AS personId, + friend.Person.firstName AS personFirstName, + friend.Person.lastName AS personLastName, + id(message) AS messageId, + CASE exists(message.`Comment`.content) + WHEN true THEN coalesce(message.`Comment`.imageFile,message.`Comment`.content) + ELSE coalesce(message.Post.imageFile,message.Post.content) + END AS messageContent, + CASE exists(message.`Comment`.content) + WHEN true THEN message.`Comment`.creationDate + ELSE message.Post.creationDate + END AS messageCreationDate + ORDER BY messageCreationDate DESC, messageId ASC + LIMIT 20 diff --git a/nebula/queries2/interactive-complex-3.ngql b/nebula/queries2/interactive-complex-3.ngql index d3bf24016..240205ddf 100644 --- a/nebula/queries2/interactive-complex-3.ngql +++ b/nebula/queries2/interactive-complex-3.ngql @@ -1,38 +1,38 @@ -MATCH (countryX:Place{name:$countryXName}) -MATCH (countryY:Place{name:$countryYName}) -MATCH (person:Person) - WHERE id(person) == $personId -WITH person, id(countryX) AS countryXId, id(countryY) AS countryYId -LIMIT 1 -MATCH (city:Place)-[:IS_PART_OF]->(country:Place) -WITH person, id(country) AS countryId, countryXId, countryYId, id(city) AS cityId -WHERE countryId IN [countryXId, countryYId] -WITH person, countryXId, countryYId, collect(cityId) AS cities -MATCH (person)-[:KNOWS*1..2]-(friend)-[:IS_LOCATED_IN]->(city) -WITH id(person) AS personId, friend, id(city) AS cityId, cities, countryXId, countryYId -WHERE personId<>id(friend) AND NOT cityId IN cities -WITH DISTINCT friend, countryXId, countryYId -MATCH (friend)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message) -WHERE - CASE - WHEN $endDate > message.`Comment`.creationDate AND message.`Comment`.creationDate >= $startDate THEN true - WHEN $endDate > message.Post.creationDate AND message.Post.creationDate >= $startDate THEN true - ELSE false - END -MATCH (message)-[:IS_LOCATED_IN]->(country) -WITH friend, id(country) AS countryId, countryXId, countryYId -WHERE countryId IN [countryXId, countryYId] -WITH friend, - CASE WHEN countryId==countryYId THEN 1 ELSE 0 END AS messageX, - CASE WHEN countryId==countryYId THEN 1 ELSE 0 END AS messageY -WITH friend, sum(messageX) AS xCount, sum(messageY) AS yCount -WHERE xCount>0 AND yCount>0 -RETURN - id(friend) AS friendId, - friend.Person.firstName AS friendFirstName, - friend.Person.lastName AS friendLastName, - xCount, - yCount, - xCount + yCount AS xyCount - ORDER BY xyCount DESC, friendId ASC - LIMIT 20 +MATCH (countryX:Place{name:$countryXName}) +MATCH (countryY:Place{name:$countryYName}) +MATCH (person:Person) + WHERE id(person) == $personId +WITH person, id(countryX) AS countryXId, id(countryY) AS countryYId +LIMIT 1 +MATCH (city:Place)-[:IS_PART_OF]->(country:Place) +WITH person, id(country) AS countryId, countryXId, countryYId, id(city) AS cityId +WHERE countryId IN [countryXId, countryYId] +WITH person, countryXId, countryYId, collect(cityId) AS cities +MATCH (person)-[:KNOWS*1..2]-(friend)-[:IS_LOCATED_IN]->(city) +WITH id(person) AS personId, friend, id(city) AS cityId, cities, countryXId, countryYId +WHERE personId<>id(friend) AND NOT cityId IN cities +WITH DISTINCT friend, countryXId, countryYId +MATCH (friend)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message) +WHERE + CASE + WHEN $endDate > message.`Comment`.creationDate AND message.`Comment`.creationDate >= $startDate THEN true + WHEN $endDate > message.Post.creationDate AND message.Post.creationDate >= $startDate THEN true + ELSE false + END +MATCH (message)-[:IS_LOCATED_IN]->(country) +WITH friend, id(country) AS countryId, countryXId, countryYId +WHERE countryId IN [countryXId, countryYId] +WITH friend, + CASE WHEN countryId==countryYId THEN 1 ELSE 0 END AS messageX, + CASE WHEN countryId==countryYId THEN 1 ELSE 0 END AS messageY +WITH friend, sum(messageX) AS xCount, sum(messageY) AS yCount +WHERE xCount>0 AND yCount>0 +RETURN + id(friend) AS friendId, + friend.Person.firstName AS friendFirstName, + friend.Person.lastName AS friendLastName, + xCount, + yCount, + xCount + yCount AS xyCount + ORDER BY xyCount DESC, friendId ASC + LIMIT 20 diff --git a/nebula/queries2/interactive-complex-4.ngql b/nebula/queries2/interactive-complex-4.ngql index 832618487..89e4d51e7 100644 --- a/nebula/queries2/interactive-complex-4.ngql +++ b/nebula/queries2/interactive-complex-4.ngql @@ -1,12 +1,12 @@ -MATCH (person:Person)-[:KNOWS]-(:Person)<-[:POST_HAS_CREATOR]-(post:Post)-[:HAS_TAG]->(`tag`:`Tag`) - WHERE id(person) == $personId AND post.Post.creationDate >= $startDate AND post.Post.creationDate < $endDate - WITH person, count(post) AS postsOnTag, `tag` - OPTIONAL MATCH (person)-[:KNOWS]-()<-[:POST_HAS_CREATOR]-(oldPost:Post)-[:HAS_TAG]->(`tag`) - WHERE oldPost.Post.creationDate < $startDate - WITH person, postsOnTag, `tag`, count(oldPost) AS cp - WHERE cp == 0 - RETURN - `tag`.`Tag`.name AS tagName, - sum(postsOnTag) AS postCount - ORDER BY postCount DESC, tagName ASC - limit 10 +MATCH (person:Person)-[:KNOWS]-(:Person)<-[:POST_HAS_CREATOR]-(post:Post)-[:HAS_TAG]->(`tag`:`Tag`) + WHERE id(person) == $personId AND post.Post.creationDate >= $startDate AND post.Post.creationDate < $endDate + WITH person, count(post) AS postsOnTag, `tag` + OPTIONAL MATCH (person)-[:KNOWS]-()<-[:POST_HAS_CREATOR]-(oldPost:Post)-[:HAS_TAG]->(`tag`) + WHERE oldPost.Post.creationDate < $startDate + WITH person, postsOnTag, `tag`, count(oldPost) AS cp + WHERE cp == 0 + RETURN + `tag`.`Tag`.name AS tagName, + sum(postsOnTag) AS postCount + ORDER BY postCount DESC, tagName ASC + limit 10 diff --git a/nebula/queries2/interactive-complex-5.ngql b/nebula/queries2/interactive-complex-5.ngql index 65fd0447f..518cc9e1c 100644 --- a/nebula/queries2/interactive-complex-5.ngql +++ b/nebula/queries2/interactive-complex-5.ngql @@ -1,12 +1,12 @@ -MATCH (person:Person)-[:KNOWS*1..2]-(friend:Person)<-[membership:HAS_MEMBER]-(forum:Forum) - WHERE id(person) == $personId AND membership.joinDate > $minDate - AND not(person==friend) - WITH DISTINCT friend, forum - OPTIONAL MATCH (friend)<-[:POST_HAS_CREATOR]-(post:Post)<-[:CONTAINER_OF]-(forum) - WITH forum, count(post) AS postCount - RETURN - id(forum) AS forumId, - forum.Forum.title AS forumTitle, - postCount - ORDER BY postCount DESC, forumId ASC - LIMIT 20 +MATCH (person:Person)-[:KNOWS*1..2]-(friend:Person)<-[membership:HAS_MEMBER]-(forum:Forum) + WHERE id(person) == $personId AND membership.joinDate > $minDate + AND not(person==friend) + WITH DISTINCT friend, forum + OPTIONAL MATCH (friend)<-[:POST_HAS_CREATOR]-(post:Post)<-[:CONTAINER_OF]-(forum) + WITH forum, count(post) AS postCount + RETURN + id(forum) AS forumId, + forum.Forum.title AS forumTitle, + postCount + ORDER BY postCount DESC, forumId ASC + LIMIT 20 diff --git a/nebula/queries2/interactive-complex-6.ngql b/nebula/queries2/interactive-complex-6.ngql index 620f9c957..a6bcc7d9b 100644 --- a/nebula/queries2/interactive-complex-6.ngql +++ b/nebula/queries2/interactive-complex-6.ngql @@ -1,5 +1,5 @@ -GO 1 to 2 steps from $personId over KNOWS bidirect where id($$)<>$personId yield id($$) as friend | \ -GO from $-.friend over POST_HAS_CREATOR reversely yield id($$) as friendPost | \ -GO from $-.friendPost over HAS_TAG where $$.`Tag`.name==$tagName yield id($^) as postWithSpecifiedTag | \ -GO from $-.postWithSpecifiedTag over HAS_TAG where $$.`Tag`.name<>$tagName yield properties($$).name as otherTagName, id($^) as commonPost | \ -group by $-.otherTagName yield $-.otherTagName as otherTagName, count($-.commonPost) as postCount | order by $-.postCount desc | limit 10 +GO 1 to 2 steps from $personId over KNOWS bidirect where id($$)<>$personId yield id($$) as friend | \ +GO from $-.friend over POST_HAS_CREATOR reversely yield id($$) as friendPost | \ +GO from $-.friendPost over HAS_TAG where $$.`Tag`.name==$tagName yield id($^) as postWithSpecifiedTag | \ +GO from $-.postWithSpecifiedTag over HAS_TAG where $$.`Tag`.name<>$tagName yield properties($$).name as otherTagName, id($^) as commonPost | \ +group by $-.otherTagName yield $-.otherTagName as otherTagName, count($-.commonPost) as postCount | order by $-.postCount desc | limit 10 diff --git a/nebula/queries2/interactive-complex-7.ngql b/nebula/queries2/interactive-complex-7.ngql index 7d2bd8390..20a9e1755 100644 --- a/nebula/queries2/interactive-complex-7.ngql +++ b/nebula/queries2/interactive-complex-7.ngql @@ -1,23 +1,23 @@ -MATCH (person:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message)<-[like:LIKES]-(liker:Person) - WHERE id(person) == $personId - WITH liker, message, like.creationDate AS likeTime, person, id(message) AS messageId - ORDER BY likeTime DESC, messageId ASC - WITH - liker, - head(collect({msg:message, likeTime:likeTime})) AS latestLike, - person - OPTIONAL MATCH p = (liker)-[:KNOWS]-(person) - RETURN - id(liker) AS personId, - liker.Person.firstName AS personFirstName, - liker.Person.lastName AS personLastName, - latestLike.likeTime AS likeCreationDate, - id(latestLike.msg) AS messageId, - CASE exists(latestLike.msg.content) - WHEN true THEN latestLike.msg.content - ELSE latestLike.msg.imageFile - END AS messageContent, - latestLike.msg.creationDate AS messageCreationDate, - p IS NULL AS isNew - ORDER BY likeCreationDate DESC, personId ASC - LIMIT 20 +MATCH (person:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message)<-[like:LIKES]-(liker:Person) + WHERE id(person) == $personId + WITH liker, message, like.creationDate AS likeTime, person, id(message) AS messageId + ORDER BY likeTime DESC, messageId ASC + WITH + liker, + head(collect({msg:message, likeTime:likeTime})) AS latestLike, + person + OPTIONAL MATCH p = (liker)-[:KNOWS]-(person) + RETURN + id(liker) AS personId, + liker.Person.firstName AS personFirstName, + liker.Person.lastName AS personLastName, + latestLike.likeTime AS likeCreationDate, + id(latestLike.msg) AS messageId, + CASE exists(latestLike.msg.content) + WHEN true THEN latestLike.msg.content + ELSE latestLike.msg.imageFile + END AS messageContent, + latestLike.msg.creationDate AS messageCreationDate, + p IS NULL AS isNew + ORDER BY likeCreationDate DESC, personId ASC + LIMIT 20 diff --git a/nebula/queries2/interactive-complex-8.ngql b/nebula/queries2/interactive-complex-8.ngql index 9f53f5484..083cbaa7e 100644 --- a/nebula/queries2/interactive-complex-8.ngql +++ b/nebula/queries2/interactive-complex-8.ngql @@ -1,12 +1,12 @@ -MATCH - (start:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message)<-[:REPLY_OF_COMMENT|REPLY_OF_POST]-(comment:`Comment`)-[:COMMENT_HAS_CREATOR]->(person:Person) - WHERE id(start) == $personId - RETURN - id(person) AS personId, - person.Person.firstName AS personFirstName, - person.Person.lastName AS personLastName, - comment.`Comment`.creationDate AS commentCreationDate, - id(comment) AS commentId, - comment.`Comment`.content AS commentContent - ORDER BY commentCreationDate DESC, commentId ASC - LIMIT 20 +MATCH + (start:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message)<-[:REPLY_OF_COMMENT|REPLY_OF_POST]-(comment:`Comment`)-[:COMMENT_HAS_CREATOR]->(person:Person) + WHERE id(start) == $personId + RETURN + id(person) AS personId, + person.Person.firstName AS personFirstName, + person.Person.lastName AS personLastName, + comment.`Comment`.creationDate AS commentCreationDate, + id(comment) AS commentId, + comment.`Comment`.content AS commentContent + ORDER BY commentCreationDate DESC, commentId ASC + LIMIT 20 diff --git a/nebula/queries2/interactive-complex-9.ngql b/nebula/queries2/interactive-complex-9.ngql index 1654133c2..13b1c3e7f 100644 --- a/nebula/queries2/interactive-complex-9.ngql +++ b/nebula/queries2/interactive-complex-9.ngql @@ -1,17 +1,17 @@ -MATCH (n:Person)-[:KNOWS*1..2]-(friend:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message) - WHERE id(n) == $personId AND (message.`Comment`.creationDate < $maxDate OR message.Post.creationDate < $maxDate) - RETURN DISTINCT - id(friend) AS personId, - friend.Person.firstName AS personFirstName, - friend.Person.lastName AS personLastName, - id(message) AS messageId, - CASE exists(message.`Comment`.content) - WHEN true THEN coalesce(message.`Comment`.imageFile,message.`Comment`.content) - ELSE coalesce(message.Post.imageFile,message.Post.content) - END AS messageContent, - CASE exists(message.`Comment`.content) - WHEN true THEN message.`Comment`.creationDate - ELSE message.POST.creationDate - END AS messageCreationDate - ORDER BY messageCreationDate DESC, messageId ASC - LIMIT 20 +MATCH (n:Person)-[:KNOWS*1..2]-(friend:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message) + WHERE id(n) == $personId AND (message.`Comment`.creationDate < $maxDate OR message.Post.creationDate < $maxDate) + RETURN DISTINCT + id(friend) AS personId, + friend.Person.firstName AS personFirstName, + friend.Person.lastName AS personLastName, + id(message) AS messageId, + CASE exists(message.`Comment`.content) + WHEN true THEN coalesce(message.`Comment`.imageFile,message.`Comment`.content) + ELSE coalesce(message.Post.imageFile,message.Post.content) + END AS messageContent, + CASE exists(message.`Comment`.content) + WHEN true THEN message.`Comment`.creationDate + ELSE message.POST.creationDate + END AS messageCreationDate + ORDER BY messageCreationDate DESC, messageId ASC + LIMIT 20 diff --git a/nebula/queries2/interactive-short-2.ngql b/nebula/queries2/interactive-short-2.ngql index 75b435906..b8656a7f8 100644 --- a/nebula/queries2/interactive-short-2.ngql +++ b/nebula/queries2/interactive-short-2.ngql @@ -1,19 +1,19 @@ -MATCH (n:Person)<-[:HAS_CREATOR]-(m:`Comment`)-[:REPLY_OF*0..100]->(p:Post) - WHERE id(n)==$personId -MATCH (p)-[:HAS_CREATOR]->(c) - RETURN - id(m) as messageId, - CASE tags(m)[0] - WHEN "Comment" THEN coalesce(m.`Comment`.imageFile,m.`Comment`.content) - ELSE coalesce(m.Post.imageFile,m.Post.content) - END AS messageContent, - CASE tags(m)[0] - WHEN "Comment" THEN m.`Comment`.creationDate - ELSE m.Post.creationDate - END AS messageCreationDate, - id(p) AS originalPostId, - id(c) AS originalPostAuthorId, - c.Person.firstName as originalPostAuthorFirstName, - c.Person.lastName as originalPostAuthorLastName - ORDER BY messageCreationDate DESC +MATCH (n:Person)<-[:HAS_CREATOR]-(m:`Comment`)-[:REPLY_OF*0..100]->(p:Post) + WHERE id(n)==$personId +MATCH (p)-[:HAS_CREATOR]->(c) + RETURN + id(m) as messageId, + CASE tags(m)[0] + WHEN "Comment" THEN coalesce(m.`Comment`.imageFile,m.`Comment`.content) + ELSE coalesce(m.Post.imageFile,m.Post.content) + END AS messageContent, + CASE tags(m)[0] + WHEN "Comment" THEN m.`Comment`.creationDate + ELSE m.Post.creationDate + END AS messageCreationDate, + id(p) AS originalPostId, + id(c) AS originalPostAuthorId, + c.Person.firstName as originalPostAuthorFirstName, + c.Person.lastName as originalPostAuthorLastName + ORDER BY messageCreationDate DESC LIMIT 10 \ No newline at end of file diff --git a/nebula/queries2/interactive-short-3.ngql b/nebula/queries2/interactive-short-3.ngql index 08ca3d0de..9981b6ce9 100644 --- a/nebula/queries2/interactive-short-3.ngql +++ b/nebula/queries2/interactive-short-3.ngql @@ -1,8 +1,8 @@ -MATCH (n:Person)-[r:KNOWS]-(friend) - WHERE id(n) == $personId - RETURN - id(friend) AS personId, - friend.Person.firstName AS firstName, - friend.Person.lastName AS lastName, - r.creationDate AS friendshipCreationDate +MATCH (n:Person)-[r:KNOWS]-(friend) + WHERE id(n) == $personId + RETURN + id(friend) AS personId, + friend.Person.firstName AS firstName, + friend.Person.lastName AS lastName, + r.creationDate AS friendshipCreationDate ORDER BY friendshipCreationDate DESC, personId ASC \ No newline at end of file diff --git a/nebula/queries2/interactive-short-4.ngql b/nebula/queries2/interactive-short-4.ngql index 9d096fe31..d6d9defe0 100644 --- a/nebula/queries2/interactive-short-4.ngql +++ b/nebula/queries2/interactive-short-4.ngql @@ -1,11 +1,11 @@ -MATCH (m) - WHERE id(m) == $commentId OR id(m) == $postId - RETURN - CASE exists(m.`Comment`.creationDate) - WHEN true THEN m.`Comment`.creationDate - ELSE m.Post.creationDate - END AS messageCreationDate, - CASE exists(m.`Comment`.content) - WHEN true THEN coalesce(m.`Comment`.imageFile,m.`Comment`.content) - ELSE coalesce(m.Post.imageFile,m.Post.content) +MATCH (m) + WHERE id(m) == $commentId OR id(m) == $postId + RETURN + CASE exists(m.`Comment`.creationDate) + WHEN true THEN m.`Comment`.creationDate + ELSE m.Post.creationDate + END AS messageCreationDate, + CASE exists(m.`Comment`.content) + WHEN true THEN coalesce(m.`Comment`.imageFile,m.`Comment`.content) + ELSE coalesce(m.Post.imageFile,m.Post.content) END AS messageContent \ No newline at end of file diff --git a/nebula/queries2/interactive-short-5.ngql b/nebula/queries2/interactive-short-5.ngql index 57a1659fc..9dd3b4b54 100644 --- a/nebula/queries2/interactive-short-5.ngql +++ b/nebula/queries2/interactive-short-5.ngql @@ -1,6 +1,6 @@ -MATCH (m)-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]->(p:Person) - WHERE id(m) == $commentId OR id(m) == $postId - RETURN - id(p) AS personId, - p.Person.firstName AS firstName, - p.Person.lastName AS lastName +MATCH (m)-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]->(p:Person) + WHERE id(m) == $commentId OR id(m) == $postId + RETURN + id(p) AS personId, + p.Person.firstName AS firstName, + p.Person.lastName AS lastName diff --git a/nebula/queries2/interactive-short-6.ngql b/nebula/queries2/interactive-short-6.ngql index bc9751cf0..cffdebf0f 100644 --- a/nebula/queries2/interactive-short-6.ngql +++ b/nebula/queries2/interactive-short-6.ngql @@ -1,8 +1,8 @@ -MATCH (m)-[:REPLY_OF*0..100]->(p:Post)<-[:CONTAINER_OF]-(f:Forum)-[:HAS_MODERATOR]->(mod:Person) - WHERE id(m) == $commentId OR id(m) == $postId - RETURN - id(f) AS forumId, - f.Forum.title AS forumTitle, - id(mod) AS moderatorId, - mod.Person.firstName AS moderatorFirstName, +MATCH (m)-[:REPLY_OF*0..100]->(p:Post)<-[:CONTAINER_OF]-(f:Forum)-[:HAS_MODERATOR]->(mod:Person) + WHERE id(m) == $commentId OR id(m) == $postId + RETURN + id(f) AS forumId, + f.Forum.title AS forumTitle, + id(mod) AS moderatorId, + mod.Person.firstName AS moderatorFirstName, mod.Person.lastName AS moderatorLastName \ No newline at end of file diff --git a/nebula/queries2/interactive-short-7.ngql b/nebula/queries2/interactive-short-7.ngql index 79412c64d..658d8ee28 100644 --- a/nebula/queries2/interactive-short-7.ngql +++ b/nebula/queries2/interactive-short-7.ngql @@ -1,15 +1,15 @@ -MATCH (m)<-[:REPLY_OF_COMMENT|REPLY_OF_POST]-(c:`Comment`)-[:COMMENT_HAS_CREATOR]->(p:Person) - WHERE id(m) == $commentId OR id(m) == $postId - OPTIONAL MATCH (m)-[:COMMENT_HAS_CREATOR|POST_HAS_CREATOR]->(a:Person)-[r:KNOWS]-(p) - RETURN - id(c) AS commentId, - c.`Comment`.content AS commentContent, - c.`Comment`.creationDate AS commentCreationDate, - id(p) AS replyAuthorId, - p.Person.firstName AS replyAuthorFirstName, - p.Person.lastName AS replyAuthorLastName, - CASE r - WHEN null THEN false - ELSE true - END AS replyAuthorKnowsOriginalMessageAuthor - ORDER BY commentCreationDate DESC, replyAuthorId +MATCH (m)<-[:REPLY_OF_COMMENT|REPLY_OF_POST]-(c:`Comment`)-[:COMMENT_HAS_CREATOR]->(p:Person) + WHERE id(m) == $commentId OR id(m) == $postId + OPTIONAL MATCH (m)-[:COMMENT_HAS_CREATOR|POST_HAS_CREATOR]->(a:Person)-[r:KNOWS]-(p) + RETURN + id(c) AS commentId, + c.`Comment`.content AS commentContent, + c.`Comment`.creationDate AS commentCreationDate, + id(p) AS replyAuthorId, + p.Person.firstName AS replyAuthorFirstName, + p.Person.lastName AS replyAuthorLastName, + CASE r + WHEN null THEN false + ELSE true + END AS replyAuthorKnowsOriginalMessageAuthor + ORDER BY commentCreationDate DESC, replyAuthorId