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.

Need help with reduce function

I have the following query

MATCH p=(a:Ne{Entity_ID:"365::RKE6110"})-[r:ROUTE*1..20]-(z:Ne{Entity_ID:"267::FTWAYNE6110"})
WHERE all(x IN relationships(p) WHERE (type(x) = "ROUTE" and x.Route_Type = "OPT" and x.Route_Rate="OC3")) 
WITH p
with  (reduce(result = "", x in filter(con in relationships(p) where type(con)="ROUTE" and con.Route_Type = "OPT" and con.Route_Rate="OC3" and not exists(con.Derived)) | result  + x.Route_ID + "," + x.Route_Rate + "," + x.Route_AENDNEID + "," + x.Route_ZENDNEID + "~~~~~")) as paths
return paths

it returns the following:

""
"267::FTWAYNE6110::1::5::3-387::INSPYRUNSUB-FOT110::1::5::2,OC3,387::INSPYRUNSUB-FOT110,267::FTWAYNE6110~~~~~294::INDUSTRIAL6110::1::5::2-387::INSPYRUNSUB-FOT110::1::5::1,OC3,387::INSPYRUNSUB-FOT110,294::INDUSTRIAL6110~~~~~294::INDUSTRIAL6110::1::5::1-311::LINCOLN6110::1::5::3,OC3,311::LINCOLN6110,294::INDUSTRIAL6110~~~~~267::FTWAYNE6110::1::5::2-311::LINCOLN6110::1::5::1,OC3,311::LINCOLN6110,267::FTWAYNE6110~~~~~"
"267::FTWAYNE6110::1::5::2-311::LINCOLN6110::1::5::1,OC3,311::LINCOLN6110,267::FTWAYNE6110~~~~~294::INDUSTRIAL6110::1::5::1-311::LINCOLN6110::1::5::3,OC3,311::LINCOLN6110,294::INDUSTRIAL6110~~~~~294::INDUSTRIAL6110::1::5::2-387::INSPYRUNSUB-FOT110::1::5::1,OC3,387::INSPYRUNSUB-FOT110,294::INDUSTRIAL6110~~~~~267::FTWAYNE6110::1::5::3-387::INSPYRUNSUB-FOT110::1::5::2,OC3,387::INSPYRUNSUB-FOT110,267::FTWAYNE6110~~~~~"

How can I

  1. filter out the first item in the list, ie. the empty string.
  2. remove the "~~~~~" from the end of each valid item in the list.

Thanks

1 ACCEPTED SOLUTION

At the end of your query, try replacing RETURN paths with:

WITH paths WHERE paths <> ''
RETURN paths

View solution in original post

1 REPLY 1

At the end of your query, try replacing RETURN paths with:

WITH paths WHERE paths <> ''
RETURN paths