0
votes

For a given vertex, I can find whether a property myproperty contains a single substring substring1, as so:

g.V(993280096)
    .filter({it.get().value("myproperty").contains("substring1")})

How can I extend this to search for multiple substrings in the same query?

Something along the lines of:

g.V(993280096)
    .filter({ it.get().value("myproperty")
                .contains(or("substring1", "substring2"))})

And is there a better way to do this instead of using lambda expressions? Note that I do not want to use the graph database (in my case JanusGraph) builtins because I'm using gremlin-python.

2

2 Answers

2
votes

You can use the new text filter predicates. On the modern sample graph you could do this for example:

gremlin> TinkerFactory.createModern().traversal().V().
           has("name", containing("ark").or(containing("os"))).values("name")
==>marko
==>josh
0
votes

Just after posting I identified a solution (though I don't know if this is the best way) using matches instead of contains:

g.V(993280096)
    .filter({ it.get().value("myproperty").matches(".* substring1.*|.* substring2.*")})