我可以在 gremlin 查询中使用 orientdb vertex/edge class 吗?

can i qualify on orientdb vertex/edge class in a gremlin query?

orientdb 具有看似 'non-standard' 的功能,能够创建特定的 classes 顶点和边。

g.createVertex('class:person')

但我不清楚 if/how 我可以通过 'standard' gremlin 获得 class 资格吗?

我看到了对语法的引用,如下所示:

g.V('@class','person')...

,但随后提到了这种绕过索引的语法。

谁能阐明这个话题?

Gremlin 似乎没有采用 Schema 特性,并不是所有的图数据库都支持 Schema,所以我认为你不能直接用 Gremlin 操作 OrientDB Schema。

无论如何,您可以使用 createVertexType() 命令通过 Gremlin 在 OrientDB 中创建 classes。

  1. 与 ODB 数据库的连接:

    g = new OrientGraphNoTx('remote:localhost/GremlinDB')
    
    ==>orientgraphnotx[remote:localhost/GremlinDB]
    
  2. 创建延伸 V:

    的顶点 class Person
    g.createVertexType('Person','V')
    
    ==>Person
    

现在,如果您查看 OrientDB Studio 中的架构,您会看到新创建的 class:

已编辑

添加两个顶点后

我们可以找到 name = 'John' 的人。

  1. 使用has():

    g.V.has('@class','Person').has('name','John')
    
    ==>v(Person)[#12:0]
    
  2. 使用has() + T运算符:

    g.V.has('@class','Person').has('name',T.eq,'John')
    
    ==>v(Person)[#12:0]
    
  3. 使用contains():

    g.V.has('@class','Person').filter{it.name.contains('John')}
    
    ==>v(Person)[#12:0]
    
  4. 使用==:

    g.V.has('@class','Person').filter{it.name == 'John'}
    
    ==>v(Person)[#12:0]
    

希望对您有所帮助