Question

I am using Neo4J Spatial cypher queries to find users in a 25KM radius, and among them find those who have the same hometown as I do. I used the following query:

START u=node(5),node=node:geom('withinDistance:[17.3,78.3,25.0]') MATCH (u)-[:hometown]->()<-[:hometown]-(o) RETURN o;

This query doesn't work the way I intended. It identifies all user nodes in the given radius and executes the same MATCH query, which is specific to user with node ID 5, for each of those nodes.

Splitting this problem into two parts, this is what I would like to combine. First part, identify all users in a 25 KM radius:

START node=node:geom('withinDistance:[17.3,78.3,25.0]') RETURN node;    

Second part, identify all users who have the same hometown as I do:

START u=node(5) MATCH (u)-[:hometown]->()<-[:hometown]-(o) RETURN o;

How do I combine these two queries into a single query?

Was it helpful?

Solution

So if I understand correctly 'node' contains all the home towns in a given radius? In which case would the following do what you want?

START u=node(5),town=node:geom('withinDistance:[17.3,78.3,25.0]') 
MATCH town<-[:hometown]-o

WITH u, o
MATCH (u)-[:hometown]->()<-[:hometown]-(o) 
RETURN o

I see Peter has answered on the mailing list. So actually my assumption was wrong, 'node' represents users which means this is the answer:

START u=node(5),o=node:geom('withinDistance:[17.3,78.3,25.0]') 
MATCH (u)-[:hometown]->()<-[:hometown]-(o) 
RETURN o
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top