Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graph 识别neo4j中两个节点之间的路径_Graph_Neo4j - Fatal编程技术网

Graph 识别neo4j中两个节点之间的路径

Graph 识别neo4j中两个节点之间的路径,graph,neo4j,Graph,Neo4j,图中有两条路径:a-B-C-D和a-B-E-F。我想为这些路径分配标识号,即a-B-C-D为1,a-B-E-F为2 可能吗?如果是,怎么做?您的意思是像持久路径ID一样?这不是直接的功能,但您可以在Cypher中的查询中完成 如果您想要某种持久性,可以始终使用索引,因此创建一个关系索引,将路径1的关系存储在路径1的键/值下 编辑:获得更多信息后,下面是一个使用索引的用例: 这将由您在索引中定义。以下是您要做的: Node a = db.createNode(); Node b =

图中有两条路径:a-B-C-D和a-B-E-F。我想为这些路径分配标识号,即a-B-C-D为1,a-B-E-F为2


可能吗?如果是,怎么做?

您的意思是像持久路径ID一样?这不是直接的功能,但您可以在Cypher中的查询中完成

如果您想要某种持久性,可以始终使用索引,因此创建一个
关系
索引,将路径1的
关系
存储在路径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);
Node a=db.createNode();
Node b=db.createNode();
Node c=db.createNode();
Node d=db.createNode();
节点e=db.createNode();
Node f=db.createNode();
关系aTob=a.createRelationshipTo(b,DynamicRelationshipType.withName(“关系”));
关系bToc=b.createRelationshipTo(c,DynamicRelationshipType.withName(“关系”));
关系cTod=c.createRelationshipTo(d,DynamicRelationshipType.withName(“关系”);
关系bToe=b.createRelationshipTo(e,DynamicRelationshipType.withName(“关系”);
关系eTof=e.createRelationshipTo(f,DynamicRelationshipType.withName(“关系”);
Index relationshipIndex=db.Index().forRelationships(“路径索引”);
字符串pathRId=UUID.randomUUID().toString();
字符串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进行搜索。您将负责在索引中维护集合ID,这里我使用UUID,但您可以使用更能代表您的信息的内容。当从索引返回时,这些关系不会以任何可重复的顺序出现

假设对于路径A-B-C-D关系R=(R1,R2,R3),对于路径A-B-E-F关系M=(M1,M2,M3,M4),关系索引是否能够保存关于R的信息(即三种可能不同的关系)?您所说的“可重复顺序”是什么意思?这意味着当查询时,您可能会返回
aTob
cTod
bToc
,顺序不正确。我相信Lucene并没有保持插入顺序,所以你会得到关系,但是它们可能不是线性的。如果我正确理解了关系的概念,没有正确顺序的关系不会杀死任何重要信息。请确认。另外,我可以在web界面中执行此操作吗?在这里可以添加关系索引,但随后必须将索引分配给路径(如何分配?),然后,如您所述,将关系索引分配给路径
relationshipIndex.add(aTob,“PathId”,pathMId)。还有一个问题。你提到我可以用密码编码持久路径ID?你能给我举个例子说明怎么做吗?(我还希望能够更改id的值)。