Gremlin - Select 基于组键的顶点

Gremlin - Select vertices based on group keys

我有一个图,其中有 2 个不同的顶点 class 具有一些相同的属性。

我需要:

  1. 根据某些属性对 class 项的所有顶点进行分组
  2. 找到共享这些属性的 class 产品的顶点
g.addV("Item").
    property("color", "green").
    property("material", "wood").
    property("shape", "round").
    property("price", 1.2).
  addV("Item").
    property("color", "green").
    property("material", "wood").
    property("shape", "round").
    property("price", .9).
  addV("Item").
    property("color", "green").
    property("material", "wood").
    property("shape", "square").
    property("price", 5).
  addV("Product").
    property("color", "green").
    property("material", "wood").next();

到目前为止我试过的是这个

g.V().has("Item", "price", P.inside(0, 10)).
  group().
    by(project("c", "m").
      by("color").by("material")). //
    local(unfold().
      project("color", "material","price","product")
        .by(select(Column.keys).select("c"))
        .by(select(Column.keys).select("m"))
        .by(select(Column.values).unfold().values("price").mean())
        .by(
          V().hasLabel("Product"). //
          has("material",P.eq(select(Column.keys).select("c"))).fold()));

我了解到 2 范围发生了变化,因此 select(Column.keys) 不再指代该组。 但是,我不知道如何在 2

的遍历中获取 c(和 m)键的值

所以我尝试用一​​种稍微不同的方法来解决它。

每组都有颜色和material组合的所有项目和产品

这样大部分工作将在您的第一步 group 中完成:

g.V().coalesce(
    hasLabel("Item").has("price", P.inside(0, 10)),
    hasLabel("Product").has("color").has("material")
    ).group()
    .by(project("c", "m").by("color").by("material"))
    .unfold()
    .where(select(values).unfold().hasLabel("Item"))
      .project("color", "material","price","product")
        .by(select(keys).select("c"))
        .by(select(keys).select("m"))
        .by(select(values).unfold().hasLabel("Item").values("price").mean())
        .by(select(values).unfold().hasLabel("Product").fold())