简体   繁体   English

Neo4j / Cypher密集节点匹配结果排序

[英]Neo4j/Cypher dense node match result ordering

I have a (:User) dense node with following relationships: 我有一个具有以下关系的(:User)密集节点:

(:User)-[:SUBSCRIBED]->(:User)
(:User)-[:CONNECTED]->(:SocialNetwork)

If I execute query below 如果我在下面执行查询

MATCH (u:User {UserId:id})
MATCH (u)-[:SUBSCRIBED]->(s)
RETURN s

I get user's subscribers ordered by recent which is expected. 我按预期得到最近订购的用户订户。

But the same query with additional matching pattern brakes this ordering 但是带有其他匹配模式的相同查询会阻止这种排序

MATCH (u:User {UserId:id})
MATCH (u)-[:SUBSCRIBED]->(s)
OPTIONAL MATCH (s)-[:CONNECTED]->(sn)
RETURN s, COUNT(sn.FriendCount)

Could someone explain why ordering by recent doesn't work in the second example. 有人可以解释为什么在第二个示例中按最近排序不起作用。

There is no guarantee of order in your query because you don't have an ORDER clause, run the same query 1000 times and I'm sure the order will change at some point. 无法保证查询中的顺序,因为您没有ORDER子句,请运行1000次相同的查询,并且我确定顺序会在某个时候发生变化。

You should order at the end of the query : 您应该在查询末尾订购:

MATCH (u:User {UserId:id})
MATCH (u)-[:SUBSCRIBED]->(s)
OPTIONAL MATCH (s)-[:CONNECTED]->(sn)
RETURN s, COUNT(sn.FriendCount)
ORDER BY s.time // ? property representing the time

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM