Gremlin case insensitive search

自作多情 提交于 2021-01-29 17:45:41

问题


I am new to Gremlin and I am using the Gremlin console to read data from a graph database. In the graph, there are vertices with label "Device". These vertices have a property "name" associated with them. I need to find out if there is a vertex that has a certain name. This check has to be case insensitive.

Suppose I was to do this in a relational database, I could write the following query:

SELECT * FROM device d WHERE LOWER(d.name) = 'mydevice'

I am searching for a function similar to 'LOWER' in Gremlin. If there isn't a function for that, can somebody tell me how I can search properties of vertices without considering alphabetic case?

Thank you.


回答1:


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:

  1. they aren't supported by all providers and therefore your code portability is reduced
  2. 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.



来源:https://stackoverflow.com/questions/58102960/gremlin-case-insensitive-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!