简体   繁体   English

使用 py2neo 和 flask 获取所有与我的输入节点连接的节点

[英]Get the nodes which are all connected with my input node using py2neo and flask

I want to fetch the connected nodes from ny neo4j database.我想从 ny neo4j 数据库中获取连接的节点。 在此处输入图像描述

For example If I give the input as 2 and then I have to fetch 1,3,4 and 5.I tried to explore the question but answer is related to neo4j only.例如,如果我将输入设为 2,然后我必须获取 1、3、4 和 5。我试图探索这个问题,但答案仅与 neo4j 有关。 I need a query with py2neo.我需要使用 py2neo 进行查询。 is there anyway i can get it?反正我能得到吗?

I tried this How to get all nodes connected to one node in neo4j graph in py2neo How to get all connected nodes in neo4j graph in py2neo我试过这个How to get all nodes connected to an node in neo4j graph in py2neo How to get all connected nodes in neo4j graph in py2neo

But these are all with neo4j not with py2neo但这些都是 neo4j 而不是 py2neo

Suppose your nodes have a property called nodeid , you can useNodeMatcher() to match node 2 (see Node Matching ), then iterate over its adjacent nodes:假设您的节点有一个名为nodeid的属性,您可以使用NodeMatcher()来匹配节点2 (请参阅节点匹配),然后遍历其相邻节点:

from py2neo import Graph, NodeMatcher

matcher = NodeMatcher(graph)

node = matcher.match(nodeid="2").first()

list(r.end_node["nodeid"] for r in graph.match(nodes=(node,)))

Otherwise, just run a cypher query:否则,只需运行 cypher 查询:

q = '''MATCH (a)-[r]-(b) where a.nodeid='2' RETURN b'''
[i for i in graph.run(q)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM