【问题标题】:How do I use spring-data-neo4j with spatial indexes and cypher?如何将 spring-data-neo4j 与空间索引和密码一起使用?
【发布时间】:2015-01-03 00:47:49
【问题描述】:

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

我有点不知道如何将它连接到一起。

有了这样的领域对象,

@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 中进行的最佳方式是什么。

【问题讨论】:

  • 你能分享你在哪里导入“IndexType.POINT”吗?

标签: neo4j spatial spring-data-neo4j


【解决方案1】:

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

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

您必须自己进行更换,例如使用 String.format

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

【讨论】:

  • 顺便说一句,您知道如何将在索引之前添加的节点添加到索引中吗?只是重新保存节点不起作用。我无法删除并重新添加它们,因为它们已经深深嵌入我的图表中。
  • 啊哈,明白了。它们没有被添加,因为旧节点没有 WKT 元素。都好! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多