Reputation: 301
i am using Neo4j 1.9.RC2 and i test the ORDER BY with WITH. What i want to do is to generate a dynamic ranking and store the current sort index into each node sorted.
i have something like : parent-[r:has_child]->rank_node I would like to do something like :
start n=node(1)
match n-[r:has_child]->rank_node
with rank_node
order by rank_node.score
set rank_node.position = "CURRENT ORDER BY INDEX"
I woul like to have a counter that increment from 0 to "n" ... I can't manage to do that ...
Here CURRENT ORDER BY INDEX is like the current index of each node return by order by.
i don't know if it is possible to do that with cyper? It would be very usefull because we can do big sorting and insert directly the position in the node to get it later directly ...
Upvotes: 1
Views: 937
Reputation: 21
MATCH (n:person)-[r:knows]->(a:phonbook)
RETURN COUNT(*) AS rank,n.mobno,r.name ORDER BY n.mobno desc //rank with relation
Upvotes: 0
Reputation: 21
MATCH (a:person)
OPTIONAL MATCH ()-[r:knows|knowsyy]->(a)
RETURN COUNT(*) AS rank,a.mobno // //rank with two direction
person=label
know and knowsyy=relation
Upvotes: 0
Reputation: 351
Talked to Michael Hunger and we solved it like this:
start n=node(0)
match n-[r:rank]->rank_node
with rank_node, n
match n-[r:rank]->rn
where rn.score <= rank_node.score
with rank_node,count(*) as pos
set rank_node.rank = pos
return rank_node;
For live example see: http://console.neo4j.org/?id=d07p7r
Upvotes: 5