Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-08-2019 11:46 PM
Hi Friends,
I am working with neo4j and i am applying sorting on my query which is getting data from various nodes, my sorting is working fine, but I am facing one issue which is, the data which starts with special characters or the data which is null are showing first is there any possible way that I can sort with the alphabet and it should sort in alphabetical order and the data with special characters should display at last; for ex: abc,Abc, Adf, bcd, Bcd, BCD, ccd, @acv, ---003abc, ^^asd, null, null, null, null
my current result is in reverse order of the example I gave above or sometimes special characters values are showing first
Below is my Query
MATCH (actor:Actor)
OPTIONAL MATCH (actor) <-[:REPRESENT_ACTOR]- (ocdactor:OCDActor)
OPTIONAL MATCH (ocdactor) -[assign:ASSIGNED_TO]-> (ocdlocation: OCDLocation {ocdYear: actor.currentOcdYear})
OPTIONAL MATCH (location:Location) <-[:REPRESENT_LOCATION]- (ocdlocation)
OPTIONAL MATCH (ocdlocation) -[:LOCATED_IN]-> (ocdregion:OCDRegion) -[:REPRESENT_REGION]-> (region: Region)
WITH actor, location, region
ORDER BY TOLOWER(toString(actor.firstName)) ASC
WITH actor, location, region
RETURN actor.firstName
skip 0 limit 25
and this is my output
07-27-2021 12:03 PM
You can use apoc.text.clean() in your ORDER BY Clause so that the special characters are not considered while sorting.
07-28-2021 06:58 AM
Hi @prnvkmr954 ,
You may not need this anymore, but if someone is reading this.
apoc.text.replace(toString(actor.firstName),'[^a-zA-Z]','')
This should work as well.
H
All the sessions of the conference are now available online