Neo4j-将匹配项应用于先前的每个匹配项 [英] Neo4j - apply match to each result of previous match

查看:66
本文介绍了Neo4j-将匹配项应用于先前的每个匹配项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:具有多个端点的图,每个端点都与主图有一个连接。在加入主图之前,此连接可能会遍历几个居间的 node-> relationship-> node 。每个连接的最后一个节点具有特定的属性。

Situation: graph with numerous end points each of which has one connection to the main graph. This connection may traverse several intervening node->relationship->node before joining the main graph. This final node where each connects has a specific property.

我有一个查询,它沿着这条路径走,并找到最终加入主图的节点。我有另一个查询,返回端点节点的列表。我应该如何使用查询2中的节点列表输入查询1,以便可以为查询2的每个成员获取查询1的结果?

I have a query that walks down this path and finds the node that ultimately joins to the main graph. I have another query that returns a list of the end-point nodes. How would I use the list of nodes from query 2 to feed into query 1 so I could get the results of query 1 for every member of query 2?

理想情况下我想要像 FOREACH 之类的东西,但是查询1以 match 语句开头。它不会做任何更改。类似于创建external_list->每个external_list_member->运行下一个查询并返回单个结果->与下一个list_member重复

Ideally I want something like FOREACH but that's out as query 1 begins with a match statement. It doesn't make any changes. Something akin to create outer_list -> each outer_list_member -> run next query and return single result -> repeat with next list_member


  • 查询1: match p ==(n {单个末端节点属性})-[r:JOINS * 1..5]-(m {连接节点属性})返回n.name,length(p)为len,m.name按len限制1排序

    -这给了我末端节点和加入节点(通过最短路径)

  • 查询2: match node_list =(n {所有末端节点的属性})

  • Query 1: match p=(n {individual end node property})-[r: JOINS*1..5]-(m { joining node property }) return n.name, length(p) as len, m.name order by len limit 1
    -- this gives me the end node and the joining node (via shortest path)
  • Query 2: match node_list = (n {property of all end nodes})

I如果我手动指定给定端节点的唯一属性( id),则可以运行查询1 并获得正确的结果。我想创建一个所有末端节点及其连接节点的列表。

I can run query 1 and get the correct results if I manually specify the unique property ("id") of a given end node. I want to create a list of all end nodes and their connecting node.

推荐答案

Cypher的 WITH 子句对于将一个查询馈入另一个查询非常有用。

Cypher's WITH clause is pretty useful for feeding one query into another. Maybe that would be useful?

http://neo4j.com/docs/stable/query-with.html

这篇关于Neo4j-将匹配项应用于先前的每个匹配项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆