如何使用Cypher在Neo4j中实现allPaths或allSimplePaths算法?

时间:2016-05-02 05:13:53

标签: neo4j cypher

我试图找到neo4j db中两个节点之间的所有路径

用于获取所有路径的查询返回错误,而当我将allSimplePaths更改为shortestPath以获取最短路径时,它可以正常工作:

MATCH (from), (to) , 
paths = allSimplePaths((from)-[*]->(to)) 
WHERE from.ID ='3007' AND to.ID in ['5575','8150', '3674']
Return paths

返回错误消息:

Invalid input '(': expected an identifier character, node labels, a property 
map, a relationship pattern, ',', USING, WHERE, LOAD CSV, START, MATCH, UNWIND, 
MERGE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN, UNION, ';' or 
end of input (line 2, column 23 (offset: 82))
"paths = allSimplePaths((from)-[*]->(to)) "

1 个答案:

答案 0 :(得分:1)

neo4j REST API支持

allSimplePathsallPaths graph algorithms,但不支持Cypher。

要获得等效的allPaths,您可以这样做:

MATCH (from), (to), paths = (from)-[*]->(to)
WHERE from.ID ='3007' AND to.ID in ['5575','8150', '3674']
Return paths

您需要使用REST API来使用allSimplePaths