查找具有所有常见中介的节点 [英] Finding nodes that have all common intermediaries

查看:91
本文介绍了查找具有所有常见中介的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个将ordersstaff匹配的系统.从概念上讲,order是要求某人做某项工作的请求,而staff是可以完成某项工作的人. order可以具有一个或多个requirements(即对谁可以从事这项工作的限制),而staff可以具有一个以上的requirements(即可以从事工作的资格).

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).

我正在尝试创建一个密码查询,该查询将给我所有具有给定order列出的requirement all 的所有staff.换句话说,我正在尝试查找与每个与给定order节点相关的requirement节点相关的所有staff节点. 我的问题:如何创建密码查询以对该业务逻辑进行建模?

I'm attempting to create a cypher query that will give me all staff that have all of the requirements 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 仅具有一个要求,Evan和Tim都有,所以他们都应该能够申请该职位.

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屋!

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