【问题标题】:Pattern matching in gremlingremlin 中的模式匹配
【发布时间】:2020-08-06 05:15:55
【问题描述】:

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

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 的确切查询和订单匹配的用户。提前致谢。

【问题讨论】:

    标签: java gremlin amazon-neptune


    【解决方案1】:

    自 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 2011-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      • 2012-10-31
      相关资源
      最近更新 更多