簡體   English   中英

neo4j密碼比較節點鏈

[英]neo4j cypher compare chain of nodes

給定graph-db中的文本,其單詞為節點:

... (:word {text:'Die'})-[:NEXT]->(:word {text:'Natur'})-[:NEXT]->(:word {text:'selbst'})-[:NEXT]->(:word {text:'ist'})-[:NEXT]->(:word {text:'Einheit'})-[:NEXT]->(:word {text:'in'})-[:NEXT]->(:word {text:'der'})-[:NEXT]->(:word {text:'Vielheit'}) ... 

現在,我想找到以下單詞中的部分:

(Natur), (Einheit) and (Vielheit)

發生在最大范圍內 10個字節點。

像這樣

// look for paths from two to nine relationships in length 
MATCH p=(n:Node)-[:NEXT*2..9]->(:Node) 

// find paths that have all of the words
WHERE ALL(label in ['Natur','Einheit','Vielheit'] where label in 
extract(node in nodes(p) | node.name ))

// return the nodes of the matching paths
RETURN nodes(p)

這是一種更好的方法。 確保在:Word(test)上加上一個索引。

// list of words
WITH ['Natur','Einheit','Vielheit'] AS texts

// find paths that include three words
MATCH path=(word1:Word )-[:NEXT*1..8]->(word2:Node)-[:NEXT*1..8]->(word3:Node)

// where each word is in your list
WHERE word1.text in texts
AND word2.text in texts
AND word3.text in texts

// and none of the words are the same
AND word1.text <> word2.text
AND word2.text <> word3.text
RETURN path

暫無
暫無

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

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