Need help to implement a generic gremlin query with Apache thinkerPop Java.

Hi Everyone, From the UI I will get one DSL query, I'm converting that into a Gremlin query. and I'm executing this gremlin query with the help of a Graph traversal source and I'm returning the query response back to UI. For now, I gave a chance to the user he can search with only three attributes (name, type, and system) so based on these three I implemented multiple gremlin queries and if else conditions. yesterday I got a new requirement for business people who want to search with multiple attributes. in these scenarios, I need to implement queries in a generic way. if I have three properties data I'm executing like this with Java code. String name ="john"; List<String> typeList = new ArrayList(); List<String> systemList = new ArrayList(); List<Map<Object, Object>> node = g.V().has("name", name).has("type", P.within(typeList)).has("system", P.within(systemList )) .local(.properties().group().by(.key()).by(__.value())).dedup().toList(); now my requirement is, I need to execute the same query with hundreds of properties. instead of writing multiple if else conditions based on property availability. is there any generic way to handle this kind of scenario. Thanks.
1 Reply
spmallette
spmallette2y ago
I'm not sure if i'm answering your question but, you can build the traversal dynamically without too much trouble:
def attrs = [type:[...], system:[...], ...]
def t = g.V().has('name',name)
attrs.each {
t = t.has(it.key, within(it.value))
}
def nodes = t.local(properties().
group().
by(key).
by(value)).
dedup().toList()
def attrs = [type:[...], system:[...], ...]
def t = g.V().has('name',name)
attrs.each {
t = t.has(it.key, within(it.value))
}
def nodes = t.local(properties().
group().
by(key).
by(value)).
dedup().toList()
Want results from more Discord servers?
Add your server