2016-05-31 67 views
0

我有查詢如何從路徑中提取標籤?

MATCH (rootPerson:Person {uuid: '650wer0a-2374-11e6-aabd-ce6wqe3145e4'}) 
MATCH (mother:Rerson)<-[rel:MOTHER*0..4]-(rootPerson) 
WITH mother 
SKIP 1 
MATCH (children:Person)-[:MOTHER]->(mother) 
MATCH (grand_children:Person)-[:FATHER|:MOTHER]->(children) 
OPTIONAL MATCH (grand_children)-[:STUDY_AT]->(uni:University)... 

而問題是,Neo4j的匹配不只是grand_children但孩子和家長的歡迎,並它的速度非常慢下來,並返回了很多useles額外的數據,我該怎麼做配套只有grand_children?

+0

這將是很好看的輸入數據的一個例子和所期望的結果。你怎麼試着得到這個結果。 –

回答

0

因爲您不必要地使用可變長度路徑模式(通過*0..4語法),所以您獲得grand_children多代。

這應該正常工作:

MATCH (rootPerson:Person {uuid: '650wer0a-2374-11e6-aabd-ce6wqe3145e4'}) 
MATCH (rootPerson)-[:MOTHER]->(mother:Person) 
MATCH (children:Person)-[:MOTHER]->(mother:Person) 
MATCH (grand_children:Person)-[:FATHER|:MOTHER]->(children) 
OPTIONAL MATCH (grand_children)-[:STUDY_AT]->(uni:University) 
...