2013-06-11 108 views
1

我有以下查詢重新安排基於另一個集合集合列表

neo4j-sh (?)$ 
$start n=node(*) match p=n-[r:LIKES]->items return n,collect(r.w),collect(items.name); 
==> +------------------------------------------------------------------------------------------------------------------+ 
==> | n     | collect(r.w)   | collect(items.name) | 
==> +------------------------------------------------------------------------------------------------------------------+ 
==> | Node[249]{name:"u1"} | [0,0.93]    | ["f5","f2"]   | 
==> | Node[248]{name:"u2"} | [0,-0.76,1,-0.66]  | ["f4","f3","f2","f1"] | 
==> +------------------------------------------------------------------------------------------------------------------+ 

我想重新排序的項目按照類似下面的

==> +------------------------------------------------------------------------------------------------------------------+ 
==> | n     | collect(r.w)   | collect(items.name) | 
==> +------------------------------------------------------------------------------------------------------------------+ 
==> | Node[249]{name:"u1"} | [0.93,0]    | ["f2","f5"]   | 
==> | Node[248]{name:"u2"} | [1,0,-0.66,-0.76] | ["f2","f4","f1","f3"] | 
==> +------------------------------------------------------------------------------------------------------------------+ 

如何RW的排序值我可以根據collect(rw)的排序值重新排列collect(items.name)的元素嗎?

+1

這可能會有幫助。 http://docs.neo4j.org/chunked/milestone/query-with.html#with-sort-results-before-using-collect-on-them – Nicholas

+0

謝謝,但我需要重新排列項目集合根據排序的值的rw集合,我不知道如何去做 – user1848018

回答

4

我覺得可能是這樣

START n=node(*) 
MATCH p=n-[r:LIKES]->items 
WITH n,r,items 
ORDER BY r.w DESC, items.name DESC 
RETURN n,collect(r.w),collect(items.name); 
+0

工作很好。謝謝 – user1848018

0

通過WITH管理您的結果,然後訂購它們。然後通過RETURN正常進行聚合。

START n=node(*) 
MATCH p=n-[r:LIKES]->items 
WITH n,r,items 
ORDER BY r.w DESC 
RETURN n,collect(r.w),collect(items.name); 
+0

我已經試過了,它只是重新排列rw,並不影響items.name的排序。我不知道如何將這兩個系列連接在一起 – user1848018

相關問題