[英]Neo4j simple paths between two nodes without specifying the maximum length
[英]Identify paths between two nodes in neo4j
我在图中有两条路径:ABCD和ABEF。 我想为这些路径分配标识号,即ABCD为1,ABEF为2。
可能吗? 如果是,怎么办?
你的意思是像一个永久的路径ID? 它没有直接提供,但您可以在Cypher的Query中完成。
如果您想让东西持久化,则可以始终使用索引,因此创建一个Relationship
索引,该索引将Path 1的Relationship
存储在Path:1的键/值下。
编辑:获得更多信息后,这是使用索引的用例:
您将需要在索引中定义它。 这是您的工作:
Node a = db.createNode();
Node b = db.createNode();
Node c = db.createNode();
Node d = db.createNode();
Node e = db.createNode();
Node f = db.createNode();
Relationship aTob = a.createRelationshipTo(b, DynamicRelationshipType.withName("RELATIONSHIP"));
Relationship bToc = b.createRelationshipTo(c, DynamicRelationshipType.withName("RELATIONSHIP"));
Relationship cTod = c.createRelationshipTo(d, DynamicRelationshipType.withName("RELATIONSHIP"));
Relationship bToe = b.createRelationshipTo(e, DynamicRelationshipType.withName("RELATIONSHIP"));
Relationship eTof = e.createRelationshipTo(f, DynamicRelationshipType.withName("RELATIONSHIP"));
Index<Relationship> relationshipIndex = db.index().forRelationships("PathIndex");
String pathRId = UUID.randomUUID().toString();
String pathMId = UUID.randomUUID().toString();
relationshipIndex.add(aTob, "PathId", pathRId);
relationshipIndex.add(bToc, "PathId", pathRId);
relationshipIndex.add(cTod, "PathId", pathRId);
relationshipIndex.add(aTob, "PathId", pathMId);
relationshipIndex.add(bToe, "PathId", pathMId);
relationshipIndex.add(eTof, "PathId", pathMId);
然后,当您要查找路径时,可以通过ID进行搜索。 您将负责维护索引中的Set ID,这里我使用UUID,但是您可以使用一些更能代表您信息的东西。 从索引返回时,这些关系将不会具有任何可重复的顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.