Neo4j を使用して、半径 50 km 内にいて、特定の日に利用可能なユーザーを見つけています。
この質問はこの他の質問に似ていますが、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 クエリを見つけることができません。
前もって感謝します、
ベンジャミン