neo4j是否适合搜索特定长度的路径 [英] Is neo4j suitable for searching for paths of specific length

查看:432
本文介绍了neo4j是否适合搜索特定长度的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是图数据库领域的一个新手.但是,让我们把它放在一边.

我有一项任务是要从起点到背面找到一定长度(或任何其他尺寸)的圆锥形路径.

因此,例如,我需要找到一个从一个节点到后面的路径,该路径长10个节点",同时具有大约15种某种权重.这只是一个例子.

neo4j是否可以通过这种方式实现?或者甚至是正确的选择?

希望我已经弄清楚了,谢谢您的回答.

致谢

解决方案

Neo4j是周期检测的不错选择. 如果您需要查找从n到长度为10的n的一条路径,则可以尝试这样的查询:

MATCH p=(n:TestLabel {uuid: 1})-[rels:TEST_REL_TYPE*10]-(n)
RETURN p LIMIT 1

此处的match子句要求Cypher使用特定的关系类型来查找从n到其自身的所有路径(正好是10跳).在Neo4j中,这称为可变长度关系.我正在使用limit 1仅返回一条路径.

结果路径可以显示为图形:

您还可以指定长度范围,例如[*8..10](距离8至10跳).

我不确定我是否理解你的意思:

大约有15种重量

如果需要,可以检查可变长度路径中的关系属性,例如权重. doc 此处中的特定示例... >

也许您还会对shortestPath()allShortestPaths()函数感兴趣,您需要了解这些结点以及起始结点,甚至可以在它们之间找到路径,甚至指定长度.

I am a total newcommer in the world of graph databases. But let's put that on a side.

I have a task to find a cicular path of certain length (or of any other measure) from start point and back.

So for example, I need to find a path from one node and back which is 10 "nodes" long and at the same time has around 15 weights of some kind. This is just an example.

Is this somehow possible with neo4j, or is it even the right thing to use?

Hope I clarified it enough, and thank you for your answers.

Regards

解决方案

Neo4j is a good choice for cycle detection. If you need to find one path from n to n of length 10, you could try some query like this one:

MATCH p=(n:TestLabel {uuid: 1})-[rels:TEST_REL_TYPE*10]-(n)
RETURN p LIMIT 1

The match clause here is asking Cypher to find all paths from n to itself, of exactly 10 hops, using a specific relationship type. This is called variable length relationships in Neo4j. I'm using limit 1 to return only one path.

Resulting path can be visualized as a graph:

You can also specify a range of length, such as [*8..10] (from 8 to 10 hops away).

I'm not sure I understand what you mean with:

has around 15 weights of some kind

You can check relationships properties, such as weight, in variable length paths if you need to. Specific example in the doc here.

Maybe you will also be interested in shortestPath() and allShortestPaths() functions, for which you need to know the end node as well as the start one, and you can find paths between them, even specifying the length.

这篇关于neo4j是否适合搜索特定长度的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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