我有这个json:
{
"name":"david", //node:Person
"TAKING":[ //link
{"name":"math"}, //node:Subject
{"name":"physics"} //node:Subject
],
"FRIEND":[ //link
{"name":"andres"}, //node:Person
{"name":"luis"} //node:Person
]
}
我有这个查询从neo4j中提取它
start person=node(*) match person-[:FRIEND]->friend, person-[:TAKING]->subject where person.name="Andres" return person, collect(distinct friend), collect(distinct subject);
结果是这样的:
==> +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
==> | person | collect(distinct friend) | collect(distinct subject) |
==> +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
==> | Node[1]{name:"Andres",title:"Developer"} | [Node[2]{name:"David",title:"Developer"},Node[3]{name:"Luis",title:"Developer"}] | [Node[5]{name:"math"},Node[6]{name:"physics"}] |
==> +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
我认为查询的这一部分可以更好:
person-[:FRIEND]->friend, person-[:TAKING]->subject
目标是避免返回部分中的 distinc 子句:
collect(distinct friend), collect(distinct subject)
我将其重写为:
subject<-[:TAKING]-person-[:FRIEND]->friend
但同样的结果。
有没有更好的方法来进行这个查询?有没有办法用密码构建原始 json?