gremlin 中的模式匹配

Pattern matching in gremlin

我有一个带有标签用户的图表,我想按名称搜索用户这是当前的实现

wg.addV("users").property("p1", "user1").property("p2", "test").next();

现在我需要搜索其 property1 或 property2 以用户在搜索中键入的字母开头的用户。

如果用户输入“u”,我需要获取其 p1 或 p2 以“u”开头的用户。 如果用户输入“use”,我需要获取 p1 或 p2 以“use”开头的用户。

我需要按相关顺序显示并限制为 10 个结果。

这是当前的实现。

g.V().or(has("users", "p1", between("use", "use" + "z")),
                    has("users", "p2", between("use", "use" + "z")))
            .limit(10))

使用这种方法无法访问用户,但它不相关,并且不包括与 p1 的确切查询和排序相匹配的用户。提前致谢。

自从 TinkerPop 3.4.0 发布后,Gremlin 也支持简单的文本谓词

在这种情况下,您应该使用 startingWith

g.V().or(
    has('users', 'firstname', startingWith('use')),
    has('users', 'lastname', startingWith('use'))
  ).limit(10)

示例:https://gremlify.com/sdgnafh8md