[英]How to properly do a OR condition in cypher neo4j
我正在為Neo4j做一個交友網站以便娛樂,並在匹配查詢中掙扎
WITH COLLECT(DISTINCT other) as to_exclude
MATCH (other:user) WHERE 'man' IN other.interest AND NOT other.email = 'some.email@gmail.com' AND other:man OR other:woman AND 'man' IN other.interest AND NOT other.email = 'some.email@gmail.com'
WITH to_exclude, COLLECT(DISTINCT other) AS result
WITH [elem IN result WHERE NOT elem IN to_exclude | elem] AS final_result
UNWIND final_result AS to_return
RETURN to_return
但這是一個可怕的查詢,因為OR迫使我重復自己
開始時,我在做類似WHERE other:man OR other:woman AND ...
但是似乎OR組的第一部分不受我的其他條件限制。
所以我不得不重復我自己condition1 AND condition2 OR condition3 AND contidion1
我想要更實用,更易讀的東西
由於某些原因,似乎沒有為Cypher記錄AND
和OR
的運算符優先級 。 但是,使用這個不錯的測試,我們可以知道AND
優先級高於OR
。
因此,查詢中的該子句(經過重新格式化以顯示有趣的模式):
WHERE
'man' IN other.interest AND NOT other.email = 'some.email@gmail.com'
AND
other:man
OR
other:woman
AND
'man' IN other.interest AND NOT other.email = 'some.email@gmail.com'
可以簡化為以下等效子句:
WHERE
(other:man OR other:woman) AND 'man' IN other.interest AND NOT other.email = 'some.email@gmail.com'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.