如何在 Neo4j 中从多个源进行 BFS

发布于 2025-01-09 01:58:13 字数 336 浏览 0 评论 0原文

我是 Java SE 和 Neo4j 的新手,当我必须为我的项目构建分析图时,我遇到了这个问题,您的任何帮助或提示将不胜感激。

我在 Neo4j 中有一个简单的有向图。

每个节点用Node{name:STRING}表示,并且每个节点的名称是唯一的,只有一种关系(s)-[:CONNECTED]->(t)。

图的大小为 3M 个节点和 8M 个边。

我得到了一个字符串列表,每个字符串都是源节点的名称。

我想知道是否有一个程序可以帮助我同时从所有源节点执行 BFS。

当然,我想找到最快的方法(可以为我的项目带来最好的性能)来解决这个问题。

感谢您的帮助!

I'm a Java SE and newbie in Neo4j, I meet this problem when I have to build an analysis graph for my project, any help or hint from you would be appreciated.

I have a simple directed graph in Neo4j.

Each node is denoted by Node{name:STRING} and the name of each node is unique, only one type of the relationship (s)-[:CONNECTED]->(t).

The size of the graph is 3M nodes and 8M edges.

And I was given a list of String, each String is the name of a source node.

I wondered may have a procedure to help me to do the BFS from all the source nodes at one time.

And of course, I want to find the fastest way (which could bring the best performance for my project) that can resolve this problem.

Thanks for all of your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心激荡 2025-01-16 01:58:13

我相信您需要 apoc.path.expandConfig。你可以设置起始节点、要遍历的关系,也可以选择 BFS。这里有一个例子

MATCH (p) WHERE p.name IN ["name1", "name2", "name3"]
CALL apoc.path.expandConfig(p, {
    relationshipFilter: "CONNECTED>",
    minLevel: 1,
    maxLevel: 10,
    bfs:true
})
YIELD path
RETURN path, length(path) AS hops
ORDER BY hops;

显然我建议您阅读这里的文档:
https://neo4j.com/labs/apoc/4.1/overview/apoc.path/apoc.path.expandConfig/#path-expander-paths-config-examples-bfs-dfs

I believe that you need the apoc.path.expandConfig. You can set the starting nodes, the relationship you want to traverse, and you can choose the BFS as well. Here there is an example

MATCH (p) WHERE p.name IN ["name1", "name2", "name3"]
CALL apoc.path.expandConfig(p, {
    relationshipFilter: "CONNECTED>",
    minLevel: 1,
    maxLevel: 10,
    bfs:true
})
YIELD path
RETURN path, length(path) AS hops
ORDER BY hops;

Obviously I recommend you to read the documentation here:
https://neo4j.com/labs/apoc/4.1/overview/apoc.path/apoc.path.expandConfig/#path-expander-paths-config-examples-bfs-dfs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文