英文:
Pattern matching in gremlin
问题
我有一个带有标签 "users" 的图形,我想按名称搜索用户,这是当前的实现:
wg.addV("users").property("p1", "user1").property("p2", "test").next();
现在我需要按照用户输入的搜索条件来搜索具有属性1或属性2以某些字母开头的用户。
如果用户输入 "u",我需要获取属性1或属性2以 "u" 开头的用户。
如果用户输入 "use",我需要获取属性1或属性2以 "use" 开头的用户。
并且我需要按相关顺序显示结果,并限制为 10 条结果。
这是当前的实现:
g.V().or(has("users", "p1", between("use", "usez")),
has("users", "p2", between("use", "usez")))
.limit(10)
通过这种方法,我能够获取用户,但结果不够相关,而且不包括与精确查询匹配并按 p1 排序的用户。提前感谢。
英文:
I have a graph with labels users and i want to search the users by name this is the current implementation
wg.addV("users").property("p1", "user1").property("p2", "test").next();
now i need to search for the users having their property1 or property2 starts with the letters as user type in search.
if user typed "u" i need to get the users whose p1 or p2 starts with "u".
if user typed "use" i need to get the users whose p1 or p2 starts with "use".
and i need to display in relevant order and limit to 10 results.
this is the current implementation.
g.V().or(has("users", "p1", between("use", "use" + "z")),
has("users", "p2", between("use", "use" + "z")))
.limit(10))
with this approach im able to the users but its not relevant and it is not including the users that match the exact query and order by p1. Thanks in advance.
答案1
得分: 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
英文:
Since the release of TinkerPop 3.4.0, Gremlin also supports simple text predicates
In this case, you should use startingWith
.
g.V().or(
has('users', 'firstname', startingWith('use')),
has('users', 'lastname', startingWith('use'))
).limit(10)
example: https://gremlify.com/sdgnafh8md
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论