1

To learn some new things I recently started a web project based on Scala, Play and Neo4j. My Play application connects to Neo4j using AnormCypher.

Everything works fine, but at the moment I am struggling to implement a proximity search feature...

I know that the Spatial Plugin is the way to go and already installed the plugin on the Neo4j server, but I don't know which configuration steps are necessary to use it (in ordinary cypher) queries.

The relevant nodes look like this:

(city: Location {name: "Zürich", lat: 47.3667, lon: 8.5500})

Is it possible to setup everything, such that I can write something like

MATCH (location: Location)-[...SOME_PATTERN
WHERE location 'withinDistance:[47.3,8.5, 100.0]'
RETURN location.name

How can I achieve this?

Robin des Bois
  • 355
  • 2
  • 6
  • 20

1 Answers1

2

The spatial plugin still uses the legacy indexing syntax in Cypher, so you must use this sort of syntax:

START location=node:spatial_index_here('withinDistance:[47.3,8.5, 100.0]')
MATCH (location)-[...SOME_PATTERN
RETURN location.name
Eve Freeman
  • 32,467
  • 4
  • 86
  • 101
  • Ok. But how can I configure the spatial plugin to index all the nodes of type `Location` using the properties `lat` and `lon`? – Robin des Bois Jun 20 '14 at 08:11
  • You have to add them manually to the index. Spatial is still a legacy-style index, AFAIK. – Eve Freeman Jun 20 '14 at 14:39
  • Ok. But how exactly is this possible? I interact with Neo4j through your library (AnormCypher). I use something like `Cypher("""MERGE (location: Location {id: {id}, ...""").on("id"-> id, ...).execute()` to create/update the nodes that should be indexed. To add a node to de spatial index I have to do do something like: `POST http://url/of/neo4j/db/data/ext/SpatialPlugin/graphdb/addNodeToLayer` with body `{"layer":"geom", "node":"http://localhost:7575/db/data/node/nodeid"}`. How do I get the `nodeid` from the merged node? Or is there a better way to achieve something simmilar with AnormCypher? – Robin des Bois Jun 20 '14 at 19:14
  • Probably a good feature/pull request for AnormCypher, but yeah that's probably the best way at the moment. – Eve Freeman Jun 20 '14 at 19:39
  • I think you overlooked a part of my question. How can I get the `nodeid`(the id of the merged node)? – Robin des Bois Jun 20 '14 at 19:54
  • 1
    Ah, yeah... you can return it after you merge it. Either return id(location) and pull it out as Long or location and pull it out as a NeoNode case class. – Eve Freeman Jun 20 '14 at 20:01
  • Something is still wrong: -merge `location` in to the graph and return `id(location) as nodeID` [with (Anorm-)Cypher] -`POST {"value":"dummy","key":"dummy","uri":"http://neo4jurl/db/data/node/nodeID"}` to `http://neo4jurl/db/data/index/node/geom` [with WS] -`POST {"layer":"geom","node":"http://neo4jurl/db/data/node/nodeID"}` to `http://neo4jurl/db/data/ext/SpatialPlugin/graphdb/addNodeToLayer` [with WS] -`GET http://neo4jurl/db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance` returns the appropriate `Location` nodes, but when I use a equivalent cypher query, nothing gets returned. – Robin des Bois Jun 21 '14 at 20:33
  • It's probably time to post a new question with more info (like what your cypher query is) – Eve Freeman Jun 22 '14 at 02:32
  • [new question](http://stackoverflow.com/questions/24349807/spatial-cypher-queries-dont-work) – Robin des Bois Jun 22 '14 at 09:52