簡體   English   中英

neo4j-查找具有強關系的節點

[英]neo4j - find nodes with strong relationship

我在圖形中將地點和人作為標簽,並且具有“ knows_the_place”關系。 喜歡:

(person)-[knows_the_place]->(place) 

一個人通常知道多個地方。

現在,我想通過地點(具有很多“地點”的共同點)找到具有“強”關系的人,例如,我想查詢共享至少3個不同地點的所有人。 (不起作用!)查詢:

MATCH
(a:person)-[:knows_the_place]->(x:place)<-[:knows_the_place]-(b:person),
(a:person)-[:knows_the_place]->(y:place)<-[:knows_the_place]-(b:person),
(a:person)-[:knows_the_place]->(z:place)<-[:knows_the_place]-(b:person)
WHERE NOT x=y and y=z
RETURN a, b

如何使用neo4j Query執行此操作?

獎勵-問題:

如果可以得到像以下這樣的訂單列表,則不給我顯示與另一個人有x個共同點的人,甚至更好。

a與BC共享7位,與bd共享5位,與ef共享2位,與a共享1位...

謝謝你的幫助!

干得好:

MATCH (a:person)-[:knows_the_place]->(x:place)<-[:knows_the_place]-(b:person)
WITH a, b, count(x) AS count
WHERE count >= 3
RETURN a, b, count

訂購:

MATCH (a:person)-[:knows_the_place]->(x:place)<-[:knows_the_place]-(b:person)
RETURN a, b, count(x) AS count
ORDER BY count(x) DESC

您也可以通過將ORDER BY添加到第一個查詢的兩者來完成這兩個操作。

請記住,這個查詢的笛卡爾積ab所以它會檢查的每個組合person節點,這可能不是很大的性能,明智的,如果你有很多的person節點。 Neo4j 2.3應該警告您有關此類查詢的信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM