graph = TinkerGraph.open()
g = graph.traversal()
g
.addV("name", "A").as("a")
.addV("name", "B").as("b")
.addV("name", "C").as("c")
.addV("name", "D").as("d")
.addV("name", "E").as("e")
.addV("name", "F").as("f")
.addV("name", "G").as("g")
.addE("hasParent").from("a").to("b")
.addE("hasParent").from("b").to("c")
.addE("hasParent").from("d").to("c")
.addE("hasParent").from("c").to("e")
.addE("hasParent").from("e").to("f")
.addE("hasParent").from("g").to("f")
Here's my closest attempt at trying to fetch the lowest common ancestor of the two vertices called "A" and "D":
g.V().has("name", within("A", "D"))
.match(
__.as("children").until(outE("hasParent").count().is(0)).repeat(out("hasParent")).emit().as("ancestors"), __.as("ancestors").path().unfold().count().as("pathLength")
)
.order()
.by(select("pathLength"))
.limit(1)
.select("ancestors")
.by("name")
// Result:
==> B // id: 2
// Expected:
==> C // id: 4
There's obviously something wrong here with this query and I've been unable to get anything better. I also feel that the .match() step may not be necessary here. I added extra as() steps for easier select()/debugging. Any hints would be appreciated - thanks.