【问题标题】:Shortest path of multiple shortest pathes多条最短路径中的最短路径
【发布时间】:2021-01-04 11:45:35
【问题描述】:

我有 2 组节点,人物和电影,我想找到离每个人最近的电影。我以这种方式找到了到最近电影的最短路径:

match path = shortestPath( (p: {id: 1)-[*]-(:MOVIE))
with path order by length(path)
return collect(path)[0]

现在,我想找到离每个人最近的电影(对于每个人,最短路径人和所有电影之间的最短路径)但是,我没有找到让每个人分开的最短路径的方法。

我希望有这样的东西:

match (p:PERSON)
with p
match path = shortestPath( (person)-[*]-(:MOVIE) )
with person.id as p_id, path ORDER BY length(path)
return collect(path)[0]

但是,查询按整个响应的长度排序。我没有找到单独订购每个 person_id 的路径集合的方法

【问题讨论】:

    标签: neo4j cypher


    【解决方案1】:

    你只需要在return语句中添加person id,这样collect就会按person id聚合

    match (p:PERSON)
    with p
    match path = shortestPath( (person)-[*]-(:MOVIE) )
    with person.id as p_id, path ORDER BY length(path)
    return p_id, collect(path)[0]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      相关资源
      最近更新 更多