[英]Neo4j Cypher return combination of matched nodes
我想使用以下架构对数据库进行一些分析:
如上图所示,有一个需要Java
和Python
知识的Vacancy1
,建议薪水等于5000$
。 此外,有一组候选人知道一切(如Candidate5
)适合薪水( Cadidate5
期望薪水等于4950$
),以及知道一些技能的候选人,如仅Java
或Python
但一起知道空缺所需的一切, 例如:
Candidate1(Java, 2000$), Candidate2(Python, 1500$)
这样的一组候选人一起知道Java
和Python
,统一工资等于3500$
。
是否可以在 Neo4j 中编写查询以找到适合这种空缺条件的所有可能的候选人集?
例如,对于上面的图片,结果应该包含类似这样的内容:
[candidate5],
[candidate1, candidate2],
[candidate1, candidate4],
[candidate3, candidate2]
请注意,结果中的候选组合可能包含任意数量的候选,而不仅限于上面示例中的 1 或 2 个。
您能否举一个这样的 Cypher 查询示例?
更新
如果我需要考虑一些额外的属性,比如经验,比如下图中的minExp
,该怎么办:
在这里,我们需要一个具有minExp = 3
的Vacancy1
的候选人。 Candidate2
的exp (experience) = 2
,从 Java 的角度来看并不适合,但与Candidate3(exp = 5)
配对,它们一起是一个很好的选择适合Vacancy1
。 是否可以改进查询以考虑此信息并进行此类组合?
我是 NEO4J APOC 函数的粉丝,所以在 APOC 中,有一个函数可以在给定列表上提供所有可能的组合。 它返回一个包含 1 或 2 或 3 或 n 个项目的列表。
With ["Java", "Python"] as skills, size(skills) as n
Match (v:Vacancy)-[:CONTAINS]->(s:Skills)<-[:CONTAINS]-(c:Candidate)
Where s.language in skills and v.salary <= c.salary
With n, v, collect(c) as candidates
With v, apoc.coll.combinations(candidates, 1, n) as allCandidatesCombi
Unwind allCandidatesCombi as combi
With v, combi where apoc.coll.sum([c in combi |combi.salary]) <= v.salary
Return v, combi
References:
n is number of skills or candidates in the result
apoc.coll.combinations will give you all possible combinations of all candidates with 1 to n candiates
Unwind is like a for loop and gives you each item of that list one at a time
apoc.coll.sum will sum up the candidates salary
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.