[英]neo4j cypher compare chain of nodes
Given a text in a graph-db with the words as 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'}) ...
Now i want to find parts of the chain where the words: 现在,我想找到以下单词中的部分:
(Natur), (Einheit) and (Vielheit)
occur within a range of max. 发生在最大范围内 10 word-nodes. 10个字节点。
Something like this... 像这样
// 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)
This is a superior approach. 这是一种更好的方法。 Be sure and and an index on :Word(test)
. 确保在: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.