在这种情况下,首先,我打开了一个 Janusgraph,创建了一些顶点和边并关闭了它;后来,我打开了同一个 Janusgraph,创建了一些顶点和边并关闭了它。
毕竟,我想找到从一个顶点到另一个顶点的路径,我发现这两个顶点不在一个路径中,因为它们创建的时间不同;但是,如果我将它们一起创建,则路径是正确的。
以下是一些用于创建的代码:
val grap = JanusGraphFactory.open("d:\\janusgraph\\janusgraph-hbase.properties")
val mgmt = grap.openManagement()
mgmt.makePropertyKey("value").dataType(classOf[String]).make()
mgmt.makeEdgeLabel("deviceid").make()
mgmt.makeVertexLabel("phone").make()
val tx = grap.newTransaction()
val phone1 = tx.addVertex(T.label, "phone", "value", "13700000001")
val phone2 = tx.addVertex(T.label, "phone", "value", "13700000002")
val phone3 = tx.addVertex(T.label, "phone", "value", "13700000003")
val phone4 = tx.addVertex(T.label, "phone", "value", "13700000004")
val phone5 = tx.addVertex(T.label, "phone", "value", "13700000005")
val dev1 = tx.addVertex(T.label, "dev", "value", "dev1")
val dev2 = tx.addVertex(T.label, "dev", "value", "dev2")
val dev3 = tx.addVertex(T.label, "dev", "value", "dev3")*/
phone1.addEdge("phone-dev", dev1, "value", "13700000001_dev1")
phone2.addEdge("phone-dev", dev1, "value", "13700000002_dev1")
phone2.addEdge("phone-dev", dev2, "value", "13700000002_dev2")
phone3.addEdge("phone-dev", dev2, "value", "13700000003_dev2")
phone4.addEdge("phone-dev", dev2, "value", "13700000004_dev2")
phone4.addEdge("phone-dev", dev3, "value", "13700000004_dev3")
tx.commit()
tx.close()
以下是查找代码:
val graph = JanusGraphFactory.open("d:\\janusgraph\\janusgraph-hbase.properties")
//val graph = JanusGraphFactory.open(configuration)
val g = graph.traversal()
val result2 = g.V().hasLabel("phone").repeat(both().simplePath()).until(bothE().count().is(1)).path().by("value").toSet
//val result = g.V().hasLabel("phone").repeat(both().simplePath()).until(bothE().count().is(1)).path().by
val it = result2.iterator()
while (it.hasNext) {
println("path=>" + it.next())
}
System.exit(1)