如何将spring-data-neo4j与空间索引和密码一起使用?

时间:2015-01-03 00:47:50

标签: neo4j spatial spring-data-neo4j

我想在Neo4j中使用spring-data-neo4j框架的空间索引。另外,我想使用cypher查询索引。数据库已嵌入。

关于如何将它连接到所有电线,我有点无能为力。

使用这样的域对象,

@NodeEntity
class Junction {
    @GraphId Long id;
    @Indexed(indexType = IndexType.POINT, indexName = "junctionLocations") Point wkt;
}
SDN应该为我维护指数。看起来是这样,因为我可以使用存储库进行空间查询:

interface JunctionGraph extends GraphRepository<Junction>, SpatialRepository<Junction> {}

junctionGraph.findWithinBoundingBox("junctionLocations", new Box(lowerBound.point, upperBound.point))

但是,据我所知,要使用cypher(通过存储库中的@Query)查询此索引,此空间索引配置将无​​法正常工作。我认为这是因为每个节点都需要手动添加到空间索引(或至少是节点的代理)。这意味着将此添加到JunctionGraph:

@Query("START n=node:junctionLocations('withinDistance:[{0}, {1}, {2}]') MATCH n-[*]->(i:Item) return i")
Collection<Item> getItemsWithin(double lat, double lon, double radius)

不起作用。

有没有人有工作食谱?对我来说这似乎有点黑魔法,我不确定在SDN中进行的最佳方式是什么。

1 个答案:

答案 0 :(得分:3)

它有效,您只需在外部创建整个查询字符串并将其作为参数传递,字符串常量中的占位符不会被替换。

@Query("START n=node:junctionLocations({0}) MATCH n-[*]->(i:Item) return i")
Collection<Item> getItemsWithin(String query)

你必须自己做替换,.e.g。使用String.format

String.format("withinDistance:[%f, %f, %f]",lat,lon,radius)