2
votes

I am using Neo4j with PHP. In my project, I have restaurant nodes. Each node has latitude, longitude and taxonomy properties.

I need to return the restaurant nodes matching user's given taxonomy with results ordered by distance from user's location (that is nearest restaurant at the first).

What is the easiest solution?

I have worked on Mongo DB and Elasticsearch,this is very easy to achieve there using special indexing. But I could not find a straightforward way in Neo4j.

3

3 Answers

2
votes

There are a couple of solutions :

2
votes

Besides the aforementioned Neo4j-Spatial, in Neo4j 3.0 there is also a built in distance() function.

See this GraphGist:

http://jexp.github.io/graphgist/idx?dropbox-14493611%2Fcypher_spatial.adoc

So if you find and match your restaurants some way you can order them by distance:

MATCH (a:Location), (b:Restaurant)
WHERE ... filtering  ...
RETURN b
ORDER BY distance(point(a),point(b)) 
1
votes

Neo4j Spatial features distance queries (among lots of other things) and also cares about ordering.