首页 > 解决方案 > Inserver 距离计算和结合 Neo4j 查询

问题描述

我有两个查询需要在 neo4j 服务器上同时执行。第一个查询需要计算距离。第二个查询需要在 JSON 响应中发送信息+计算的距离请建议我如何在 Neo4j 中结合上述查询?

查询1:

=======

WITH point({ longitude:76.91859, latitude:8.487992, height: 100 }) AS p1, point({ latitude:8.495548 , longitude:76.93015, height: 100 }) AS p2 RETURN distance(p1,p2) AS dist

查询2:

  MATCH (qperson:QuarantinedPersons) 
    WHERE qperson.name = 'Raman' 
    CREATE (thereturnrecord:theDetails{theid: qperson.id,thename: 
    qperson.Name,thedetails:qperson.details,thelat:qperson.lat,thelong:qperson.long,thedistance:2000}) 
   RETURN thereturnrecord

预期输出,类似于:

 [
      {
        "thereturnrecord": {
         "identity": 3,
         "labels": [
            "theDetails"
          ],
          "properties": {
        "thelong": "76.91859",
        "thelat": "8.487992",
        "thedetails": "XYZ",
        "thedistance": 2000(Obtained from the query),
        "theid": "1"
      }
    }
  }

标签: neo4jcypher

解决方案


[更新]

这是一个组合查询:

WITH
  point({ longitude:76.91859, latitude:8.487992, height: 100 }) AS p1,
  point({ latitude:8.495548 , longitude:76.93015, height: 100 }) AS p2
MATCH (q:QuarantinedPersons) 
WHERE q.name = 'Raman' 
CREATE (thereturnrecord:theDetails{
  theid: q.id,
  thename: q.Name,
  thedetails: q.details,
  thelat: q.lat,
  thelong: q.long,
  thedistance: distance(p1, p2)
}) 
RETURN thereturnrecord

其中,如果 2的参数作为参数point传递,并且: p1p2

MATCH (q:QuarantinedPersons) 
WHERE q.name = 'Raman' 
CREATE (thereturnrecord:theDetails{
  theid: q.id,
  thename: q.Name,
  thedetails: q.details,
  thelat: q.lat,
  thelong: q.long,
  thedistance: distance(point($p1), point($p2))
}) 
RETURN thereturnrecord

推荐阅读