Matt
Matt

Reputation: 468

'Or' operator for node properties in Gremlin assigned to one subgraph

I have a Janusgraph database which contains nodes with the label 'Paper', the node properties 'paperTitle' and 'year' and the edge type 'References'.

I'm trying to write a query that will allow me to select two papers by title and all their references and assign that result to a subgraph.

I can select one paper using two conditions like this:

sg = g.V().
     and(has('Paper', 'paperTitle', 'ladle pouring guide'), has('Paper', 'year', '1950')).
     inE('References').
     subgraph('sg1').
     cap('sg1').
     next()

Using this query as my starting point I had hoped I could do this:

sg = g.V().
     or(has('Paper', 'paperTitle', 'ladle pouring guide'), has('Paper', 'paperTitle', 'the development of the human mandibular joint')).
     inE('References').
     subgraph('sg1').
     cap('sg1').
     next()

But this returns a subgraph with 0 nodes and 0 edges.

I saw this page in the Janusgraph documentation http://tinkerpop.apache.org/docs/current/reference/#or-step but it seems to only describe selections of multiple edges not multiple node properties.

Is it possible to create this kind of subgraph or do I need to runs these as two separate queries?

Upvotes: 1

Views: 275

Answers (1)

stephen mallette
stephen mallette

Reputation: 46216

I don't see why you can't do this in one query and I'm not sure why your traversal doesn't work, however I would write it as:

sg = g.V().
     has('Paper', 'paperTitle', within('ladle pouring guide', 
                                       'the development of the human mandibular joint')).
     inE('References').
     subgraph('sg1').
     cap('sg1').
     next()

Upvotes: 1

Related Questions