2

我正在使用 Neo4j 查找半径为 50 公里且在特定日期可用的用户。

这个问题与其他问题类似,但索引自 Neo4J 2.0 以来发生了变化,因此该解决方案不起作用。

我使用 Neo4j 2.2.1、Neo4j-spatial 0.14 和 py2neo / py2neo-spatial 与图形进行交互。

要将用户几何图形添加到我使用的图表中:

def create_geo_node(graph, node, layer_name, name, latitude, longitude):
  spatial = Spatial(graph)
  layer = spatial.create_layer(layer_name)
  node_id = node._id
  shape = parse_lat_long(latitude, longitude)
  spatial.create_geometry(geometry_name=name, wkt_string=shape.wkt, layer_name="Users", node_id=node_id)

..它根据需要创建空间节点。

然后我想通过执行以下操作来查询图表:

START user=node:Users('withinDistance:[4.8,45.8,100]')
MATCH period=(start_date:Date)-[:NEXT_DAY*]->(end_date:Date)
    WHERE start_date.date="2014-03-03" AND end_date.date="2014-03-04"
    UNWIND nodes(period) as nodes_in_period
    OPTIONAL MATCH (nodes_in_period)<-[a:AVAILABLE]-(user:User)
    RETURN user.uuid, count(a)/count(nodes(period))

但查询返回:

Index `Users` does not exist 
  • 似乎 py2neo spatial.create_layer(..) 创建了图层而不是索引(但应该吗?..因为索引现在是 Neo4j 1.* 的“遗产”)

  • 使用 py2neo 空间 find_within_distance 有效,但由于它使用 REST api,我无法发出考虑其他参数的混合请求

  • 据我了解,自 Neo4j 2.0 起,START 已被弃用,但我无法在 Neo4j 2.2 中为 withinDistance 找到正确的 Cypher 查询

先感谢您,

本杰明

4

2 回答 2

2

create_layer创建一个与 Neo 的索引不同的“空间”索引。它实际上创建了一个图形,为您建模一些边界框,以便您可以对数据执行空间查询。您不需要直接引用此索引。把它想象成一个 GIS 图层。

可以检查您的图表并挖掘出编写您自己的密码查询所需的节点属性。

但您也可以使用 py2neo 空间 API find_within_distance http://py2neo.org/2.0/ext/spatial.html#py2neo.ext.spatial.plugin.Spatial.find_within_distance

希望这可以帮助。

于 2015-06-11T12:52:06.800 回答
0

我认为这些链接可能很有用:* Neo4j Spatial 'WithinDistance' Cypher 查询返回空,而 REST 调用返回数据 * https://github.com/neo4j-contrib/spatial/issues/106

但问题不是你没有得到任何结果,而是索引上的错误......这就是我感到困惑的原因。

你能用一些 REST 查询(创建层和空间节点)直接测试 neo4j 空间,看看会发生什么吗?

否则,对于您关于密码开始条件的问题,您只需将此条件放入匹配项中,如下所示:

MATCH 
    user=node:Users('withinDistance:[4.8,45.8,100]'),
    period=(start_date:Date {date:'2014-03-03'})-[:NEXT_DAY*]->(end_date:Date {date:'2014-03-04'})
UNWIND nodes(period) as nodes_in_period
OPTIONAL MATCH (nodes_in_period)<-[a:AVAILABLE]-(user:User)
RETURN user.uuid, count(a)/count(nodes(period))
于 2015-06-11T20:38:01.087 回答