Using Neo4J Spatial Cypher queries with other cond

2019-05-21 10:37发布

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?

1条回答
对你真心纯属浪费
2楼-- · 2019-05-21 11:08

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
查看更多
登录 后发表回答