我有以下查询,它返回类别的名称和ID,但我也想要与该类别相关的照片计数。有没有办法计算照片计数并返回包
MATCH (user:User {id:"xyz"),
(root:Category {id:"123"})
MATCH path=(user)<-[:OWNER]-(photo)-[:PHOTO_OF]->(categories)
WITH distinct categories as cats, user, photo
MATCH catpath=(cats)<-[:CHILD_OF*]-(root)
WHERE photo.is_private=false
WITH [x in nodes(catpath) | x.id] as p, root, catpath, user
WHERE p[-1] = "123"
return distinct [x in nodes(catpath) | [x.id, x.name]] as paths
答案 0 :(得分:1)
这对你有用吗?
MATCH
(user:User {id:"xyz"}),
(root:Category {id:"123"}),
path=(user)<-[:OWNER]-(photo)-[:PHOTO_OF]->(categories)
WHERE photo.is_private=false
WITH DISTINCT categories as cats, root, COUNT(photo) AS count
MATCH catpath=(cats)<-[:CHILD_OF*]-(root)
RETURN {numPhotos: count, path: [x in nodes(catpath) | {id: x.id, name: x.name}]} AS result;
我也清理了查询,以提高查询效率并删除冗余检查。