Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js neo4j:由收款人支付的限额和订单_Node.js_Neo4j_Cypher - Fatal编程技术网

Node.js neo4j:由收款人支付的限额和订单

Node.js neo4j:由收款人支付的限额和订单,node.js,neo4j,cypher,Node.js,Neo4j,Cypher,考虑一下这个cypher查询 MATCH (a : User)-[c : Commented]->(b) RETURN DISTINCT a.username AS username, b.postId AS postId, COLLECT({commentBody : c.comments, commentedOn : c.time})[0..5] AS commentData LIMIT 20; 查询从1开始返回me“c”,并将其限制为5。我怎样才能拿到最后五个“c”,然后按“注释”

考虑一下这个cypher查询

MATCH (a : User)-[c : Commented]->(b) RETURN DISTINCT a.username AS
username, b.postId AS postId, COLLECT({commentBody : c.comments,
commentedOn : c.time})[0..5] AS commentData LIMIT 20;
查询从1开始返回me“c”,并将其限制为5。我怎样才能拿到最后五个“c”,然后按“注释”排序。注**“a”和“c”之间关系的数量未知,可能是1,也可能是1000

我试图实现的是,返回多达20个“a”节点,其中包含该路径的最后5个相关关系“c”。
例如,你的instagram主页可能有20篇帖子,每一篇都可能在一个帖子集中有很多评论,对吗?我可以做到,直到这里,我可以收集前5个关系“c”,我这里的问题是,如果我必须匹配20个“a”节点,我如何收集最后5个关系“c”。

如果我理解正确,您希望获取最后5个注释,即按时间戳排序(降序),并获取前5个注释。用于将查询链接在一起,例如:

MATCH (a : User)-[c : Commented]->(b)
WITH DISTINCT
  a.username AS username,
  b.postId AS postId,
  c.comments AS commentBody,
  c.time AS commentedOn
ORDER BY commentedOn DESC
LIMIT 5
RETURN
   username, collect({postId : postId, commentBody : commentBody, commentedOn : commentedOn}) AS commentData
LIMIT 20

您需要使用WITH,以便可以使用查询的第一部分匹配20个用户,然后使用这些用户收集每个用户的最后5条注释

像这样的事情应该管用,否则至少会让你迷失方向

MATCH (a : User)
// only interested in users that have commented
WHERE (a)-[:Commented]->()
WITH a LIMIT 20
// for those 20 users, get all their comments
MATCH (a)-[c : Commented]->(b)
// order results by time so we collect comments in order later
WITH a, c, b
ORDER BY c.time DESC
// return results, getting only the slice of 5 collected comments for each user
RETURN a.username AS username, COLLECT({commentBody : c.comments, commentedOn : c.time, postId : b.postId})[0..5] AS commentData

这将限制整个匹配结果i-e,如果我想得到20个用户的评论,并且每个用户可以有n个评论作为关系,那么它就失败了。它将给我20个结果,这将是一个用户+评论组合。例如,如果一个用户评论了30次,这将向我发送一个用户和他的19条评论。我打算做的是从每个人那里获取20个用户和最多5条评论。@RishikRohan好的,我现在更了解它了。你能在帖子里更新你的问题吗?但我仍然不清楚的是,您希望获取哪20个用户?更新了问题陈述,如果需要更多解释,请告诉我。选择这20个用户的标准是什么?只要有20个用户在任何帖子上发表了评论,并且有了这20个用户,他们每个人在任何帖子上都能得到最后5条评论?@InverseFalcon-yup