cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Neo4j Sorting is not working with special character

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

2 REPLIES 2

You can use apoc.text.clean() in your ORDER BY Clause so that the special characters are not considered while sorting.

Bennu
Graph Fellow

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