我找到以下代码来创建边缘(如果它尚不存在)。
g.V().hasLabel("V1")
.has("userId", userId).as("a")
.V().hasLabel("V1").has("userId", userId2)
.coalesce(
bothE("link").where(outV().as("a")),
addE("link").from("a")
)
它工作正常,但我想创建顶点和边(如果它们不存在于 1 个查询中)。
我用新图尝试以下代码,它只是创建新顶点,但它们之间没有关系。
g.V().hasLabel("V1")
.has("userId", userId).fold()
.coalesce(
unfold(),
addV("V1").property("userId", userId1)
).as("a")
.V().hasLabel("V1").has("userId", userId2).fold()
.coalesce(
unfold(),
addV("V1").property("userId", userId2)
)
.coalesce(
bothE("link").where(outV().as("a")),
addE("link").from("a")
)
感谢丹尼尔·库皮茨 (Daniel Kuppitz)JanusGraph 谷歌组 https://groups.google.com/d/msg/janusgraph-users/AS-_W9SaWS4/rJTInVJ_CwAJ。我找到了解决办法。我将其重新发布在这里,供有需要的人使用。
您的查询有两个问题。第一个是它不能按预期工作的原因:fold() 步骤。使用fold()会破坏路径历史记录,但您可以通过在子遍历中执行该部分来轻松解决它:
g.V().has("V1","userId", userId1).fold().
coalesce(unfold(),
addV("V1").property("userId", userId1)).as("a").
map(V().has("V1","userId", userId2).fold()).
coalesce(unfold(),
addV("V1").property("userId", userId2))
coalesce(inE("link").where(outV().as("a")),
addE("link").from("a"))
第二个问题是两者的结合和淘汰。你应该使用bothE/otherV
, outE/inV
or inE/outV
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)