Hey, could you please please help me with a query.
I have my fancy graph with cities and relations types (like :AVIA, :TRAIN, etc). The initial query works fine, still, it does not return relations types. I've tried a bunch of variation, but due to lack of experience have no idea how to do it correctly. Here is the query:
MATCH (a:City {name:'Kyiv'}), (b:City {name:'Lviv'})
MATCH p=(a)-->(b)
WITH collect(p) as paths
CALL apoc.spatial.sortByDistance(paths) YIELD path, distance
RETURN path, distance
Result
│[{"name":"Kyiv","latitude":50.4500336,"longitude":30.5241361},{ !!!!!!HERE MUST BE A TYPE!!!!!!! },{"name":"Lviv","latitude":49.841952,"longitude":24.0315921} │467.37874514968337]
It works if I do not set latitude and longitude, in other case the query returns error. Variable r not defined (line 5, column 14 (offset: 180)) "RETURN type(r), path, distance"
The query was like this (and I've tried several variants): MATCH (a:City {name:'Kyiv'}) -[r]-> (b:City {name:'Poltava'}) MATCH p=(a)-[]->(b) WITH collect(p) as paths CALL apoc.spatial.sortByDistance(paths) YIELD path, distance RETURN type(r), path, distance LIMIT 1
Still the problem is solved if I simply export a json -- it has all details included.
Hey, thanks for the hint. Still sortPathsByDistance(paths) -- if I understand correctly -- is sortByDistance(paths) now. And it does not work, unfortunately. I tried several combinations, and I guess the issue is that of apoc, so I cannot return relations, and this is unreasonable... so I presume there is a mistake somewhere.
It is soooo frustrating, now I have mapping errors...
Cannot map (6)-[5:NEXT]->(0) to a nested result object for property path.
The query works in neo4j browser and in spring it is a disaster.
Here is what I've got:
[
{
"path": null,
"distance": 467.37874514968337
},
{
"path": null,
"distance": 919.730947031842
},
{
"path": null,
"distance": 1078.4521131704946
},
{
"path": null,
"distance": 1285.5076747122657
},
{
"path": null,
"distance": 1310.505104404419
}
]
...and in "evaluate" result of debugger I can see full details, but only if I use Object as a returning value.
Please if you have any idea how to populate those details from neo, pls help.
The result of Object in debugger (but not in json) are like this:
result = {ArrayList@8722} size = 5
0 = {RouteRepository$RouteData@8724}
"RouteRepository.RouteData(path=[(6)-[5:NEXT]->(0)], distance=467.37874514968337)"
The query is the same, and it is perfectly fine. I just cannot populate the nested objects in java.
MATCH (a:City {name:$departure}), (b:City {name:$arrival})\n" +
"MATCH p=(a)-->(b)\n" +
"WITH collect(p) as paths\n" +
"CALL apoc.spatial.sortByDistance(paths) YIELD path, distance\n" +
"RETURN paths, distance LIMIT 5