How to get vertex matching multiple properties?

47 views
Skip to first unread message

Johnny Weng Luu

unread,
Feb 3, 2012, 3:48:22 AM2/3/12
to ne...@googlegroups.com
How can I match vertex matching multiple properties using Gremlin?

eg.

Instead of this single matching:

"products = g.idx('vertices')[[name: 'Foo']].next()",

Something like:

"products = g.idx('vertices')[[name: 'Foo', parentName: 'Bar']].next()",

But matching only vertexes with both of the property values.

Johnny

James Thornton

unread,
Feb 3, 2012, 4:11:55 AM2/3/12
to ne...@googlegroups.com
> "products = g.idx('vertices')[[name: 'Foo', parentName: 'Bar']].next()",

A traversal might be better suited for this. 

Instead of storing parentName as a property, try modeling it with a "parent" edge from Foo to Bar...

Foo -- parent --> Bar

...then do...

start = g.idx('vertices')[[name: 'Foo']].as('products')
parent = start.out('parent').filter(it.name == 'Bar')
products = parent.back('products').iterate()

Or as a one-liner...

products = g.idx('vertices')[[name: 'Foo']].as('products').out('parent').filter(it.name == 'Bar').back('products').iterate()

-James

Johnny Weng Luu

unread,
Feb 3, 2012, 6:10:27 AM2/3/12
to ne...@googlegroups.com
Thanks that helped a lot.

But is it possible to retrieve an indexed vertex by multiple keys?

Johnny

James Thornton

unread,
Feb 3, 2012, 6:47:40 AM2/3/12
to ne...@googlegroups.com
> But is it possible to retrieve an indexed vertex by multiple keys?

I don't think there's presently an interface for that using the default Lucene Exact index. But you could do something like this...

g.idx('vertices')[[name: 'Foo']].filter{it.parentName == 'Bar'}

- James

Johnny Weng Luu

unread,
Feb 3, 2012, 7:04:02 AM2/3/12
to ne...@googlegroups.com
Ah okay .. good to know. Thanks!

Johnny

Marko Rodriguez

unread,
Feb 3, 2012, 10:58:34 AM2/3/12
to ne...@googlegroups.com
Hey,

Also, for speed, note that:

filter{it.parentName == 'Bar'}

is SLOWER than

filter{it.getProperty('parentName') == 'Bar'}

* Reason being: it.parentName makes use of an "Missing Property" exception catch and converts the property into the method call it.getProperty(). A reflection trick you can do with Groovy.

HTH,
Marko.

Michael Hunger

unread,
Feb 3, 2012, 12:18:34 PM2/3/12
to ne...@googlegroups.com, ne...@googlegroups.com
But as with groovy/grails you can create the method on the missing method and then it is a faster method call for the next accesses

Von meinem iPhone gesendet

Johnny Weng Luu

unread,
Feb 3, 2012, 12:29:48 PM2/3/12
to ne...@googlegroups.com
Oh didn't know that.

Seems that if I'm using the latter the strong selling point of Groovy is gone.

But on the other hand I like performance boosts :)

Johnny
Reply all
Reply to author
Forward
0 new messages