2013-05-18 32 views
2

是否有可能通過「屬性」使用where子句和現在的結果的「索引/位置」進行排序?Neo4j/Cypher:排序和在哪裏,知道排序結果的位置

我的意思是,當使用排序順序時,我們需要能夠知道排序結果的位置。

想象一下,有100萬用戶節點的記分牌,我通過用戶node.score執行命令,其中「name = user_name」並且我不想知道用戶的當前等級。我沒有找到如何做到這一點使用ORDER BY ...

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位置!)

回答

2

此功能不今天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

+0

謝謝你,它的偉大工程......但我覺得workaroud爲O(n * n)的複雜性? – 7vingt