2

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?

Ninja
  • 5,082
  • 6
  • 37
  • 59

1 Answers1

2

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
Mark Needham
  • 2,098
  • 17
  • 19
  • 1
    'node' contains all the users in a given radius. Among these users, I needed to find those who share the hometown as I do. I came up with this query which works, do let me know if you think I have structured the query correctly: START u=node(5),node=node:geom('withinDistance:[17.3,78.3,25.0]') MATCH (u)-[:hometown]->()<-[:hometown]-(node) RETURN node; – Ninja Aug 11 '13 at 14:02