neo4j是否可以通过关系进行排序和过滤? 例如:
我有关系密切的花园和孩子(父亲,母亲,兄弟,姐妹),我想用这种类型的过滤器列出具有关系的花园和孩子:
if the gardien is the father of the kid:
then return (father, kid)
else if the kid doesn't have the father :
then return his (mother, kid)
else if the kid doesn't have the father or mother:
then return his (brother, kid)
otherwise :
return his (sister, kid)
如何用cypher发出这样的请求?
先谢谢您
答案 0 :(得分:1)
如果您可以添加(父亲,母亲,...)作为关系的属性,我认为此查询可以为您提供帮助
MATCH (:Human {type:'kid'})-[r:Relate]-(gurdian:Human)
WITH m ,CASE r.type
WHEN 'father' THEN 0
WHEN 'mother' THEN 1
WHEN 'brother' THEN 2
ELSE 3
END as value
RETURN gurdian ORDER BY value
我的数据测试:
Create (b:Human {type: 'kid'}),
(f:Human {type: 'father'}),
(m:Human {type: 'mother'}),
(br:Human {type: 'brother'}),
(b)-[:Relate {type: 'father'}]->(f),
(b)-[:Relate {type: 'mother'}]->(m),
(b)-[:Relate {type: 'brother'}]->(br)