MATCH (category:Category {id:'123'}),
(stream:Stream {id:'567'})
OPTIONAL MATCH path=(stream)-[:CONTAINS]->(categories:Category)-[:CHILD_OF*0..50]->(category)-[:CHILD_OF*0..50]->(subcats2:Category)<-[:PHOTO_OF]-(photo)
with stream, subcats2, photo
OPTIONAL MATCH (stream)<-[:PARTICIPANT_OF]-(users:User)-[:OWNER]->(photo)-[:PHOTO_OF]->(subcats:Category
return photo
我想要這樣的查詢;Neo4j條件相交的可選匹配
如果流contains
類別做的第一可選
如果流(已)participants
用戶做第二個可選
是否已經都返回的照片
但在上面的查詢的交點;它就像聯合查詢,如果流有參與者或用戶,則返回OK,但如果它具有類別和用戶,則無法取交集。
需要像
MATCH (category:Category {id:'123'}),
(stream:Stream {id:'567'})
MATCH (stream)-[:CONTAINS]->(categories:Category)
WITH count(categories) as cat_count
IF cat_count > 0
MATCH path=(stream)-[:CONTAINS]->(categories:Category)-[:CHILD_OF*0..50]->(category)-[:CHILD_OF*0..50]->(subcats2:Category)<-[:PHOTO_OF]-(photo)
with stream, subcats2, photo
MATCH (stream)-[:PARTICIPANT_OF]->(users:User)
WITH count(users) as user_count
IF user_count > 0
MATCH (stream)<-[:PARTICIPANT_OF]-(users:User)-[:OWNER]-> (photo)-[:PHOTO_OF]->(subcats:Category
return photo
任何想法?
是'subcats'應該是'subcats2'? – cybersam
他們是不同的subcats,它不是重要的部分@cybersam – tunaktunak
我並不想暗示這是最重要的事情:-),但它確實會影響任何潛在的解決方案。 – cybersam