如何使用vertex属性为java应用程序获取顶点?

nnt7mjpx  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(296)

我们有一个user.java类。

public class User{

    private String name;
    private List<String> phone;

   //setters and getters
}

在这个节点中

{
   "name": "Ibney",
   "phone": ["123","704","456"]
}

现在我想使用手机获取用户顶点。我提供了电话号码列表,但不同的一个和字符串704之一是匹配的。如何获取用户顶点。像这样用我用的任何东西

List<String> phone = new ArrayList<>();
phone.add("204");
phone.add("704");

List<Vertex> vertex = g.V().hasLabel(label.getLabel()).has(phone, P.within(phone)).toList();

匹配值是704,但不幸的是这不起作用。

dgiusagp

dgiusagp1#

如果将属性存储为实际的java列表 within step不会看里面。你需要 unfold 是的。沿着以下路线:

gremlin> phone = ["123","704","456"] 
gremlin> g.addV('test').property('phone',phone)  

==>v[60867]

gremlin> g.V().has('phone').where(values('phone').unfold().is(within(phone)))

==>v[60867]

然而,并不是所有的数据库都支持像列表一样直接存储java类型。为了获得更大的灵活性,您可能需要使用创建列表。

gremlin> g.addV('test').
......1>       property(list,'phone',"123"). 
......2>       property(list,'phone',"704"). 
......3>       property(list,'phone',"456")

==>v[60869]

gremlin> g.V().has('phone',within(phone))

==>v[60869]

相关问题