Gremlin Sort shows upper case results first instead of alphabetical order using order().by(' ')

530 views
Skip to first unread message

Ismail Awan

unread,
Jul 11, 2018, 12:06:00 PM7/11/18
to Gremlin-users
While trying to sort using
order().by("property",decr) or
order().by("property",decr)

while property is a string

Uppercase 'Z' comes before lowercase 'a' or vice versa

Can anyone provide some help in this regard ??

Daniel Kuppitz

unread,
Jul 11, 2018, 7:54:05 PM7/11/18
to gremli...@googlegroups.com
That's how Strings are supposed to get sorted. If you're looking for case-insensitive ordering, you should

a) store the lowercased value of your String property as another property (slower writes, faster reads) or
b) use a lambda to order by lowercased values (faster writes, slower reads):

.order().by {a, b -> b.value('property').toLowerCase().compareTo(a.value('property').toLowerCase()) }

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/5970f918-59e5-4803-abd6-555131d34e5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ismail Awan

unread,
Jul 12, 2018, 4:56:49 AM7/12/18
to Gremlin-users
Thats exactly what i needed case-insensitive ordering.

I will look into storing as lower cased values,

Thanks



On Thursday, July 12, 2018 at 1:54:05 AM UTC+2, Daniel Kuppitz wrote:
That's how Strings are supposed to get sorted. If you're looking for case-insensitive ordering, you should

a) store the lowercased value of your String property as another property (slower writes, faster reads) or
b) use a lambda to order by lowercased values (faster writes, slower reads):

.order().by {a, b -> b.value('property').toLowerCase().compareTo(a.value('property').toLowerCase()) }

Cheers,
Daniel

On Wed, Jul 11, 2018 at 8:57 AM, Ismail Awan <ismailsh...@gmail.com> wrote:
While trying to sort using
order().by("property",decr) or
order().by("property",decr)

while property is a string

Uppercase 'Z' comes before lowercase 'a' or vice versa

Can anyone provide some help in this regard ??

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Ismail Awan

unread,
Jul 12, 2018, 7:31:47 AM7/12/18
to Gremlin-users
.order().by {a, b -> b.value('property').toLowerCase().compareTo(a.value('property').toLowerCase()) }
I checked in gremlin console and its working perfectly

How would i implement the query in java ??

Robert Dale

unread,
Jul 12, 2018, 8:06:50 AM7/12/18
to gremli...@googlegroups.com

Ismail Awan

unread,
Jul 12, 2018, 10:12:01 AM7/12/18
to Gremlin-users
Thanks @Robert and @Daniel

For future reference for someone like me,
I used following java code for the queries provided by daniel.

descending order
order().by((a,b) -> b.value("property").toString().toLowerCase().compareTo(a.value("property").toString().toLowerCase()))

ascending order
order().by((a,b) -> a.value("property").toString().toLowerCase().compareTo(b.value("property").toString().toLowerCase()))
Reply all
Reply to author
Forward
0 new messages