我在寫一個查詢食譜的查詢。我想用匹配查詢的食譜返回當前的用戶交互(喜歡等)。Cypher查詢在查找多個記錄時不返回關係
該查詢返回正確的當前用戶的所有交互:
MATCH (recipe)<-[reaction:REACTS]-(beholder:User {cuid: 'some-id'})
RETURN reaction
然而,當我在比賽添加到現有的搜索查詢,該reaction
變量是空的每一條記錄:
MATCH (recipe:Recipe)
OPTIONAL MATCH (recipe)-[a:CONTAINS]->(i:Ingredient)
OPTIONAL MATCH (recipe)-[:IS]->(c:Category)
OPTIONAL MATCH (recipe)<-[:AUTHORED]-(u:User)
OPTIONAL MATCH (recipe)<-[reaction:REACTS]-(beholder:User {cuid: 'some-id'})
WHERE ALL(
ingredient IN ['tomato', 'banana']
WHERE (recipe)-[:CONTAINS]->(:Ingredient {name: ingredient})
)
AND ALL(
category IN ['smoothie']
WHERE (recipe)-[:IS]->(:Category {name: category})
)
RETURN DISTINCT recipe,
{username: u.username, cuid: u.cuid} AS author,
{love: reaction.love, favorite: reaction.favourite} AS interactions,
collect(DISTINCT {name: i.name, amount: a.amount}) AS ingredients,
collect(DISTINCT {name: c.name}) AS categories
查詢我用來獲取單個食譜的ID儘管它應該如此:
MATCH (recipe:Recipe {cuid: {recipeCuid}})
OPTIONAL MATCH (recipe)-[a:CONTAINS]->(i:Ingredient)
OPTIONAL MATCH (recipe)-[:IS]->(c:Category)
OPTIONAL MATCH (recipe)<-[:AUTHORED]-(u:User)
OPTIONAL MATCH (recipe)<-[reaction:REACTS]-(beholder:User {cuid: {beholderCuid}})
RETURN recipe,
{username: u.username, cuid: u.cuid} AS author,
{love: reaction.love, favorite: reaction.favorite} AS interactions,
collect(DISTINCT {name: i.name, amount: a.amount}) AS ingredients,
collect(DISTINCT {name: c.name}) AS categories
任何指向我在做什麼錯的?
1.如果從查詢中刪除WHERE子句,結果如何?也許'WHERE'子句過濾掉了'reaction'不爲空的所有匹配項。 2.這可能沒有什麼區別,但在你的第一個查詢中,你沒有指定'recipe'應該有一個'Recipe'標籤。 –
它在我刪除where子句時起作用!任何想法,我可以如何使它與'WHERE'子句一起工作? – Amygdaloideum
如果只保留'WHERE'子句中的一個條件,即只檢查'ingredient'還是僅檢查'category',會發生什麼? –