2014-07-10 103 views
1

查詢,在V2.0.3工作現在升級到Neo4j的V2.1.2後,Cypher支架查詢不起作用

START n = NODE(67635) 
MATCH (n:publication) 
WHERE n.status <> 0 
OPTIONAL MATCH (n)-[re:contains|can_use]->(e) 
WHERE (e:article) AND (e.status <> 0 AND re.status <> 0)  
WITH n, e 
ORDER BY e.created DESC 
WITH n, COLLECT(e) AS ce  
RETURN n, ce[0..10], LENGTH(ce) 

,在V2.1.2我得到了同樣的查詢以下錯誤:

Cannot match on a pattern containing only already bound identifiers (line 2, column 1)\n\"MATCH (n:publication)\"\n ^\n [exception] => SyntaxException\n [fullname] => org.neo4j.cypher.SyntaxException\n [stacktrace] => Array\n  (\n   [0] => org.neo4j.cypher.internal.compiler.v2_1.SemanticChecker$$anonfun$check$1.apply(SemanticChecker.scala:40)\n   [1] => org.neo4j.cypher.internal.compiler.v2_1.SemanticChecker$$anonfun$check$1.apply(SemanticChecker.scala:40)\n 

我知道如何解決它,但我想避免在整個項目中修復查詢,如果可能的話。 任何其他解決方案?

回答

1

你可以配置你的Neo4j數據庫使用舊的Cypher編譯器/解析器,例如CYPHER 2.0

你可以做到這一點每個查詢或在全球範圍內neo4j.properties

cypher_parser_version=CYPHER 2.0 
0

重構到這一點:

MATCH (n:publication) 
WHERE ID(n)=67635 AND n.status <> 0 
OPTIONAL MATCH (n)-[re:contains|can_use]->(e) 
WHERE (e:article) AND (e.status <> 0 AND re.status <> 0)  
WITH n, e 
ORDER BY e.created DESC 
WITH n, COLLECT(e) AS ce  
RETURN n, ce[0..10], LENGTH(ce) 

還要注意的是匹配多個關係類型的,現在需要一個冒號爲每種類型的前綴:

old: OPTIONAL MATCH (n)-[re:contains|can_use]->(e) 
new: OPTIONAL MATCH (n)-[re:contains|:can_use]->(e)