如何使用py2neo RelationshipMatcher
或类似的方法将所有具有第二级连接的节点返回到原始节点?
我可以使用以下Cypher查询:
MATCH (u)-[:has]-()-[:validates]-(result)
WHERE u.UserName = "Dave"
RETURN result
下面的图表会给我路线A,B和C
但是,对同一查询使用db.evaluate(query
(如下所示)只会返回第一个匹配节点(即Route A
)
from py2neo import Graph, Node, Relationship, NodeMatcher, RelationshipMatcher
def get_routes(username):
query = "MATCH (u)-[:has]-()-[:validates]-(result) WHERE u.UserName = '"'{}'"' RETURN result".format(username)
result = db.evaluate(query)
db = Graph("bolt://X.X.X.X:7687", username = "neo4j", password = "password")
get_routes("Dave")
如下所示,将返回连接到我的用户的一阶节点(即Condition1
,Condition2
)。
如何修改此代码以交付匹配的二阶节点?
u = db.nodes.match("User", UserName=username).first()
matcher = RelationshipMatcher(db)
nodes = matcher.match((u, None), "has")
答案 0 :(得分:0)