是否可以通过带有位置子句的“属性”和现在结果的“索引/位置”进行订购?

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

想象一下一个拥有100万个用户节点的记分板,我对用户node.score进行了排序,其中“名称= 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中节点的当前排名/位置!)

最佳答案

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

关于neo4j - Neo4j/Cypher:按位置排序,知道结果在排序中的位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16627076/

10-10 03:13