1

Can someone please help me understand how spatial indexes are supposed to work in Spring-Data-Neo4j?

I've created a simple index:

@NodeEntity
class Junction {
    @GraphId Long id;
    @Indexed(indexType = IndexType.POINT, indexName = "Location") String wkt;

    void setPosition(double longitude, double latitude) {
        this.wkt = String.format("POINT(%f %f)",longitude, latitude).replace(",",".");
    }
}

This appears to work - when I persist Junctions for which I have set a position, they appear to be added to a spatial index. (When I 'match (m) return m' from the Neo4j web console, I see that there is a node added to the spacial root with an 'id' property that matches the node added).

However, when I remove the node I added with the repository's delete, it doesn't automatically remove the node from the spacial index root.

Do I have to do something manual to get the node removed from the spatial index, or is this a feature?

Here's what the Neo4j database looks like before and after the deletion of the added junction:

Before:

Node[0]
        Labels: [ReferenceNode]
        Relationships
                0 -[LAYER]-> 1
        Properties: [[name, spatial_root]]
Node[1]
        Labels: []
        Relationships
                1 -[RTREE_ROOT]-> 2
                1 -[RTREE_METADATA]-> 3
                0 -[LAYER]-> 1
        Properties: [[layer, junctionLocations], [ctime, 1416295060307], [geomencoder, org.neo4j.gis.spatial.WKTGeometryEncoder], [layer_class, org.neo4j.gis.spatial.EditableLayerImpl], [geomencoder_config, wkt]]
Node[2]
        Labels: []
        Relationships
                1 -[RTREE_ROOT]-> 2
                2 -[RTREE_REFERENCE]-> 5
        Properties: [[bbox, [100.0, 100.0, 100.0, 100.0]]]
Node[3]
        Labels: []
        Relationships
                1 -[RTREE_METADATA]-> 3
        Properties: [[maxNodeReferences, 100], [totalGeometryCount, 1]]
Node[4]
        Labels: [Junction, _Junction]
        Relationships
        Properties: [[longitude, 100.0], [latitude, 100.0], [wkt, POINT(100.000000 100.000000)]]
Node[5]
        Labels: []
        Relationships
                2 -[RTREE_REFERENCE]-> 5
        Properties: [[wkt, POINT (100 100)], [id, 4], [gtype, 1], [bbox, [100.0, 100.0, 100.0, 100.0]]]

After:

Node[0]
        Labels: [ReferenceNode]
        Relationships
                0 -[LAYER]-> 1
        Properties: [[name, spatial_root]]
Node[1]
        Labels: []
        Relationships
                1 -[RTREE_ROOT]-> 2
                1 -[RTREE_METADATA]-> 3
                0 -[LAYER]-> 1
        Properties: [[layer, junctionLocations], [ctime, 1416295060307], [geomencoder, org.neo4j.gis.spatial.WKTGeometryEncoder], [layer_class, org.neo4j.gis.spatial.EditableLayerImpl], [geomencoder_config, wkt]]
Node[2]
        Labels: []
        Relationships
                1 -[RTREE_ROOT]-> 2
                2 -[RTREE_REFERENCE]-> 5
        Properties: [[bbox, [100.0, 100.0, 100.0, 100.0]]]
Node[3]
        Labels: []
        Relationships
                1 -[RTREE_METADATA]-> 3
        Properties: [[maxNodeReferences, 100], [totalGeometryCount, 1]]
Node[5]
        Labels: []
        Relationships
                2 -[RTREE_REFERENCE]-> 5
        Properties: [[wkt, POINT (100 100)], [id, 4], [gtype, 1], [bbox, [100.0, 100.0, 100.0, 100.0]]]

Clearly the junction has gone, but the spatial index doesn't know about the removal.

Dr Joe
  • 718
  • 5
  • 19
  • It actually should remove the node-reference from the index. – Michael Hunger Nov 18 '14 at 01:02
  • That's what I would have expected. So is this a bug in SDN or a configuration issue my code? – Dr Joe Nov 18 '14 at 05:13
  • I'm using SDN version 3.2.1, btw. – Dr Joe Nov 18 '14 at 05:35
  • Could also be a spatial index issue, I heard it sometimes does not correctly remove entries. – Michael Hunger Nov 20 '14 at 09:48
  • Looking at the source for both spatial, and SDN, it does appear that there are any unit tests around modifying geometry within spatial indexes and checking that the searches return the right results. I'm therefore sure that there are many bugs in this area :(. If I wanted to work with someone toward improving the situation in this area, do you know who the best person to speak to would be? – Dr Joe Nov 20 '14 at 10:11

0 Answers0