Search code examples
javadatastax-enterprisegremlintinkerpop3datastax-enterprise-graph

Vertex label based traversal


I have a use case to do a traversal based on the label of the vertex for searched name.

For example : There are three kinds of labels Org, Asset and Class(all containing name as the keys of vertices) in our system. And if we do a search by name and it finds out to be a Org vertex , I want a particular traversal to carry out , to exclude extra traversal to other vertices.

So in this mechanism when we have to find a label for that vertex a global search has to be carried out which is quite not a solution.

So what mechanism is suggested instead( for this fulltext/partial text search across graph)?


Solution

  • You could do something like

    inject('Org','Asset','Class').flatMap{
      g.V().has(it.get(),'name', 'theNameYouArSearchingFor')
    }.
    choose(label()).
      option('Org',   someTraversalForOrg()).
      option('Asset', someTraversalForAsset()).
      option('Class', someTraversalForClass())
    

    I think that in order to use an index lookup, you need to use the three-value form of has() -- that is, you need to specify a label. But if you want to use an index lookup for multiple labels, you have to do three separate lookups, and combine them with flatMap as presented here.