查找具有所有公共中介的节点 [英] Finding nodes that have all common intermediaries
问题描述
我正在创建一个系统,在该系统中我们将 orders
与 staff
进行匹配.从概念上讲,order
是要求某人完成某项工作,而 staff
是可以完成该工作的人.一个订单
可以有一个或多个要求
(即限制谁可以做这项工作),一个staff
可以再有一个>要求
(即工作资格).
I'm creating a system in which we match orders
to staff
. Conceptually, an order
is a request for person to do some work, and a staff
is a person who can do that work. An order
can have one or more requirements
(i.e. restrictions on who can do the work), and a staff
can have one more more requirements
(i.e. qualifications to do work).
我正在尝试创建一个密码查询,该查询将为我提供所有 staff
的 all 给定的 requirement
订单
.换句话说,我试图找到与给定 order
节点相关的每个 requirement
节点相关的所有 staff
节点.我的问题是:如何创建密码查询来为该业务逻辑建模?
I'm attempting to create a cypher query that will give me all staff
that have all of the requirement
s listed by a given order
. Said another way, I'm trying to find all staff
nodes that are related to every requirement
node that is related to a given order
node. My question is: how do I create a cypher query to model that business logic?
例如,考虑以下示例数据:
As an example, consider the following sample data:
- 我的示例数据的图片视图
- 或者,这里是 一个我的数据的交互式控制台
查看 orderId: 1 节点.它与标记为 RN 和 ER IV 的两个节点具有 requires
关系.换句话说,第 1 条命令要求任何申请人都具有 RN 资格和 ER IV 资格.碰巧员工 Evan (staffId: 1) 具有这两个资格,因此他应该能够申请该职位.工作人员 Tim 满足其中一项要求,但不能同时满足这两项要求,因此他不能申请该职位.此外,orderId: 2 只有一个要求,埃文和蒂姆都有,所以他们都应该能够申请那份工作.
Look at the orderId: 1 node. it has a requires
relationship to two nodes, labeled RN and ER IV. In order words, order #1 requires any applicants to have the RN qualification and the ER IV qualification. It so happens that staff member Evan (staffId: 1) has both of those qualifications, so he should be able to apply for that job. The staff member Tim has ONE of those requirements, but not both, so he should not be able to apply for that job. Additionally, orderId: 2 only has one requirement, which Evan and Tim both have, so they should both be able to apply for that job.
所以本质上,如果我从订单 1 开始,我只想找回 Evan.如果我从第 2 号订单开始,我想找回 Evan 和 Tim*.
So in essence, if I were to start with order #1 I would want to get back only Evan. If I were to start with order #2 I would want to get back Evan and Tim*.
以下查询已完成一半.它将为我提供从给定订单到工作人员一次一个要求的所有独特路径.但是,它不会检查是否满足每个需求路径(这意味着目前它仅适用于只有一个需求的订单):
The following query is half way there. It will give me all unique paths from a given order to a staff member one requirement at a time. However, it does not check that EVERY requirement path is satisfied (which means currently it will only work for orders that only have a single requirement):
start o=node(2)
match o-[:requires]->req<-[:hasRequirement]-s
return o, req, s;
那么我的选择是什么?我可以以某种方式检查未知数量的匹配关系的存在吗?或者我是否需要以不同的方式为我的数据建模?
So what are my options? Can I somehow check the presence of an unknown number of matching relationships? Or will I need to model my data a different way?
*我在设置示例数据时犯了一个错误.Tim 应该与 RN 相关联,以便他有资格获得订单 #2.
* I made a mistake when setting up my sample data. Tim should have been associated with RN so that he qualified for order #2.
推荐答案
我想这个密码语句可以解决您的问题:
I guess this cypher statement solves your problem:
start o=node(2)
match o-[:requires]->req<-[:hasRequirement]-p
with o, p, count(req) as c
where length(o-[:requires]-()) = c
return p, c
这篇关于查找具有所有公共中介的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!