English 中文(简体)
如何确定节点之间的关系数目?
原标题:How to set number of relations between nodes?
  • 时间:2024-02-02 15:50:04
  •  标签:
  • neo4j
  • cypher

I have created a transport route of station nodes connected by a :CONNECTION type session, if it is a transfer, I have a :EXCHANGE session type. I m looking for a route using a query

MATCH path = (from:Station {id: 61})-[:IN]->(sec_from:Section),
              (to:Station {id: 131})<-[:OUT]-(sec_to:Section),
              route=(sec_from)-[:CONNECTION|EXCHANGE*]->(sec_to)
RETURN route;

If I want to search for direct connections only, I use: route=(sec_from)-[:CONNECTION*]->(sec_to) , it works. If I want to limit the number of connections to 5-10, I use: route=(sec_from)-[:CONNECTION*5..10]->(sec_to) also works. But if I want to have a connection of type :CONNECTION 1-100 and at the same time type :EXCHANGE 0-3, the query doesn t work:

MATCH path = (from:Station {id: 61})-[:IN]->(sec_from:Section),
              (to:Station {id: 131})<-[:OUT]-(sec_to:Section),
              route=(sec_from)-[:CONNECTION*1..100|EXCHANGE*0..3]->(sec_to)
RETURN route;

正确的yn子是什么?

增 编

最佳回答

根据你在问题中所写的内容,直截了当的办法是在<代码>中增加对每一关系类型数目的限制。 WHERE 条款:

MATCH path = (from:Station {id: 61})-[:IN]->(sec_from:Section), 
      (to:Station {id: 131})<-[:OUT]-(sec_to:Section), 
      route = (sec_from)-[r:CONNECTION|EXCHANGE*1..103]->(sec_to) 
WHERE 1 <= size([rel IN r WHERE rel:CONNECTION]) <= 100 
      AND size([rel IN r WHERE rel:EXCHANGE]) <= 3
RETURN route;

根据您的数据,这种过滤器可能效率不高,因为它可能会在多个途径中铺设;在<代码>上丢弃之前,有三条类型的<代码>EXCHANGE。 WHERE 条款阶段。

问题回答

暂无回答




相关问题
NoSQL or Ehcache caching?

I m 利用春天/Hibernate/Tomcat和我sql数据库建造一个路标网络

How does FlockDB compare with neo4j?

Both FlockDB and neo4j are open source frameworks for keeping large graph dataset. Anyone familiar enough with both products to write a comparison?

Problem Working with Neo

I downloaded Neoclipse Source and downloaded the Neo4J source. However some of the classes that the Neoclipse source file refers to are not found in the Neo4J source. Are they deprecated? Can I get ...

Neo4j Documentation [closed]

I ve been looking into setting up and trying out Neo4j on Amazon EC2 however I seem to have hit a road block with finding documentation that I can use. For example, this page mentions "Clustering, ...

热门标签