Hi all,
I'm working on a query that involves a spatial search and filtering based on relationships between nodes. The goal is to find the nearest points of interest (POIs) within a certain distance and return their names, ordered by their distance and the number of repetitions.
Here’s the query I’m currently using:
MATCH (ca:Calle {cod:7})-[]-(i:Inmueble)
WITH ca, i AS inmuebles
LIMIT 100
CALL spatial.withinDistance('Data.osm', inmuebles.punto, 5)
YIELD node, distance
WITH node AS n, distance, ca
MATCH (c:OSMWay:Direccion)-[:GEOM]->(n)
WHERE c.name IS NOT NULL
WITH c, ca, distance
ORDER BY distance ASC
LIMIT 10
RETURN c.name, ca.nombre, COUNT(c.name) AS repeticiones
ORDER BY repeticiones DESC
LIMIT 1;
- How can I improve the performance of this query, especially considering the use of
spatial.withinDistance
and the multipleWITH
clauses? - Are there any indices or strategies that could help with optimizing spatial queries?
- Should I consider restructuring the query for better readability and performance, or is there a more efficient way to achieve the same result?