Neo4j / Cypher:按顺序排列,知道结果在排序中的位置

时间:2013-05-18 17:30:34

标签: neo4j cypher

是否可以通过带有where子句的“property”订购,现在是结果的“index / position”?

我的意思是,在使用排序顺序时,我们需要能够知道排序中结果的位置。

想象一下拥有100万用户节点的记分牌,我在用户node.score上做了一个订单,其中“name = user_name”,我不想知道用户的当前排名。我没有找到如何使用订单...

    start game=node(1)
    match game-[:has_child_user]->user
    with user
    order by user.score
    with user
    where user.name = "my_user"
    return user , "the position in the sort";

预期结果将是:

node_user |秩

(我不想在客户端获取一百万个条目以了解ORDER BY中节点的当前排名/位置!)

1 个答案:

答案 0 :(得分:3)

此功能目前在Cypher中不存在。你有一个例子,它会在SQL中看起来像什么?以下是符合条件的东西吗? (只是草图,不工作!)

(您的代码)

start game=node(1)
match game-[:has_child_user]->user
with user
order by user.score

(+此代码)

with user, index() as rank
return user.name, rank; 

如果您有更多想法或想要开始攻击,请在https://github.com/neo4j/neo4j/issues

打开一个问题

暂时可以解决这个问题:

start n=node(0),rank_node=node(1) 
match n-[r:rank]->rn 
where rn.score <= rank_node.score 
return rank_node,count(*) as pos;

有关实例,请参阅:http://console.neo4j.org/?id=bela20