Officially, Gremlin currently only has three text predicates at this time as exposed by TextP
: startingWith
, endingWith
and containing
(as well as their negations), but their default implementations are case sensitive:
gremlin> g.V().has('person','name',containing('ark')).values('name')
==>marko
gremlin> g.V().has('person','name',containing('Ark')).values('name')
gremlin>
Depending on the TinkerPop-enabled graph database that you use, you may have this sort of feature available to you as well as other more advanced search options (e.g. regex). For example, JanusGraph supports full-text search as case insensitive as well as a host of other options. DS Graph also has a rich text search system on top of the basic Gremlin options. So, if you have a explicit need for the type of search you describe you may need to look into the options provided by individual graph systems.
While it's not recommended for a number of reasons you can use a lambda:
gremlin> g.V().filter{it.get().value('name').toUpperCase() == 'MARKO'}.values('name')
==>marko
The downside to lambdas are that:
- they aren't supported by all providers and therefore your code portability is reduced
- they force requests to be evaluated in a manner that can be more costly than a traversal that strictly uses Gremlin steps.
TinkerPop is slowly identifying commonalities among search options provided by different vendors and will continue to generalize those features as opportunity presents itself, so that they are available as first-class citizens in the Gremlin language itself.
UPDATE: As of TinkerPop 3.6.0, Gremlin now has a TextP.regex
predicate that can help with these sorts of searches:
gremlin> g.V().has('name', TextP.regex('[M|m].*o')).elementMap()
==>[id:1,label:person,name:marko,age:29]
gremlin> g.V().has('name', TextP.regex('(?i)M.*O')).elementMap()
==>[id:1,label:person,name:marko,age:29]
Note that the (?i)
enables the Java's Pattern.CASE_INSENSITIVE
pattern matching mode.