简体   繁体   English

Neo4j图形数据库与属性的关系

[英]Neo4j graph database relationship with properties

I'm developing something for learning graph databases.I'm finding the shortest path that query in the following segment: 我正在开发一些用于学习图形数据库的东西,在以下部分中找到了查询的最短路径:

start n=node(5),m=node(45) match p=shortestPath(n-[*..1000]->m) return p,length(p)

But I have problem about that.That query will return the shortest path and not considered with ROUTE properties.I mean, I want to get shortest path with a relation, if there is exist same property. 但是我对此有问题。该查询将返回最短路径,并且不考虑ROUTE属性。我的意思是,如果存在相同的属性,我想获得具有关系的最短路径。

Node A ==> :RELATION(ROUTE_ID=180) ==> Node B ==> :RELATION(ROUTE_ID=180) ==> NODE C ==> :RELATION(ROUTE_ID=197) 节点A ==>:RELATION(ROUTE_ID = 180)==>节点B ==>:RELATION(ROUTE_ID = 180)==> NODE C ==>:RELATION(ROUTE_ID = 197)

When I call the normal shortest path function, it gives me relationships by random properties.I want to focus on properties also.What is the keyword for that? 当我调用普通的最短路径函数时,它通过随机属性给我关系,我也想关注属性,这的关键词是什么? How can I fix that problem or How can I improve that query? 如何解决该问题或如何改进该查询?

Thanks. 谢谢。

If all relationships with the ROUTE_ID property have a specific relationship type, say 'ROUTE', then you can do this: 如果所有具有ROUTE_ID属性的关系都具有特定的关系类型,例如“ ROUTE”,则可以执行以下操作:

START n=node(5), m=node(45)
MATCH p=shortestPath(n-[:ROUTE*..1000]->m)
RETURN p,length(p);

Otherwise, you can do this: 否则,您可以这样做:

START n=node(5), m=node(45)
MATCH p=shortestPath(n-[r*..1000]->m)
WHERE all(x IN r WHERE has(x.ROUTE_ID))
RETURN p,length(p);

The former approach should be much faster. 前一种方法应该更快。

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

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