Neo4j最短路径(BFS)距离查询变体 [英] Neo4j shortest path (BFS) distances query variants

查看:441
本文介绍了Neo4j最短路径(BFS)距离查询变体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太了解Neo4j,请多多包涵.我有一个大的(1M节点)无向,无权图.假设我神奇地将此图导入了Neo4j. Neo4j查询引擎(密码)可以支持以下几种类型的查询吗?

I do not know Neo4j so, bear with me. I have a big (1M nodes) undirected, unweighted graph. Assume I magically import this graph to Neo4j. Can the Neo4j query engine (cypher) support those the following types of queries?

  • 范围查询.带给我所有的节点(及其距离) 距特定节点3跳的距离之内
  • 带来最短路径(BFS)距离(因为图形是无向的 且未加权)在特定节点和一组节点之间.
  • 在特定节点和所有其他图形节点之间保持最短路径(BFS)距离.
  • Range queries. Bring all me nodes (and their distances) that are within 3 hops distance from a specific node
  • Bring the shortest-path (BFS) distance (since the graph is undirected and unweighted) between a specific node and a set of nodes.
  • Bring the shortest-path (BFS) distance between a specific node and all other graph nodes.

如果实际上可以进行这些类型的查询,而没有递归类型实现,而直接来自Cypher,那么我应该期望哪种类型的性能(几秒钟,几秒钟或几分钟)?

If those types of queries are actually possible, without a recursive type implementation but straight from Cypher, What type of performance should I expect (few seconds, many seconds or minutes)?

推荐答案

是的,cypher可以完成所有这些事情.

Yes, cypher can do all of those things.

范围查询如下所示:

MATCH path=(a:MyNode { name: "Foo"})-[:myRelationshipType*1..20]->(b));

这为您提供了从MyNode到给定关系类型的1至20跳之间的所有"b"节点.匹配路径是一个变量,可以对其应用各种密码功能.因此,对于每条路径,您都可以询问它有多长,中间是什么,等等. 密码refcard 显示的功能适用于路径,以了解您可以使用它们做什么

That gives you all "b" nodes that are between 1 and 20 hops from MyNode with the given relationship type. The matched path is a variable, which can have various cypher functions applied to it. So for each path, you can ask how long it is, what's in the middle, and so on. The cypher refcard shows functions that apply to paths to get a sense for what you can do with them.

最短路径搜索可在此处找到并使用密码中的shortestPathallShortestPaths函数.

Shortest-path searches can be found here and use the shortestPath and allShortestPaths functions in cypher.

如果您想获得从某物到图形中其他所有东西的最短路径,则可以在一个查询中完成;最短路径将从匹配头"节点和尾"节点开始.如果找到从一件事到其他事物的最短路径,则头节点匹配项将是您感兴趣的节点,而尾节点匹配项将是图中的任何节点".例如. MATCH (a:MyNodeOfInterest), (b), p=shortestPath((a)-[*]->(b)).因此,如果要在一百万个节点图中查找从一件事到其他一切的最短路径,则可以在一个查询 but 中执行此操作无论您使用哪种图形数据库,都需要一些时间.

If you wanted to get the shortest path from something to basically everything else in the graph, you could do that in one query; the shortest path would start with matching a "head" node, and a "tail" node. In the case of finding shortest path from one thing to everything else, the head node match would be your node of interest, and the tail node match would be "any node in the graph". E.g. MATCH (a:MyNodeOfInterest), (b), p=shortestPath((a)-[*]->(b)). So you could do this in one query, but, if you're trying to find shortest paths from one thing to everything else in a one million node graph, that's going to take some time, no matter what graph database you use.

就性能而言,没有人能真正准确地回答该问题.这将取决于许多不同的因素,例如:

In terms of performance, nobody can really accurately answer that question. It will depend on a lot of different factors like:

  1. 总数据量
  2. 索引策略
  3. 您对节点标签的使用/滥用以及关系类型
  4. 总路径长度
  5. JVM/内存/缓存配置.

这篇关于Neo4j最短路径(BFS)距离查询变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆