使查询适应 return 个正确的结果

Adapt query to return correct results

我有以下查询。在这里,我收集所有行和技能,将行展开为行并检查候选人技能是否在我想要的所有技能中,我检查与该候选人相关的每项技能是否在我想要的所有技能列表中。 我需要以某种方式更改查询,因为我想要查询 return me Candidates only if "Knows" all required skills AND for every skill has same or more years of experience. 简而言之,如果候选人知道所有技能并且每项技能都有相同或更多年的经验,我想要这个节点,否则没有。 有什么想法吗?

WITH  [
        {entity_id: 7, years_of_experience: 5},
        {entity_id: 23776, years_of_experience: 1 },
        {entity_id: 17477, years_of_experience: 1 }
      ]  AS rows
UNWIND rows AS row
MATCH  (s:SkillNode)
  WHERE s.entity_id = row.entity_id
WITH  collect(row) as rows, collect(s) as allSkills, s
UNWIND rows as row
MATCH (c:CandidateNode)-[r:KNOWS]->(s)
  WHERE  (r.years_of_experience>=row.years_of_experience AND s in allSkills)
WITH c, collect(distinct r) as rels, collect(distinct s) as skills, allSkills
  WHERE ALL(sk in allSkills where sk in skills)
RETURN skills, rels, c;

以下不是您想要的确切查询,因为我使用的是技能名称而不是 entity_id,但它可能与您想要的相似。

步骤:

  1. Put required skills and years of experience in one list (rows)
  2. Search each required skills in SkillNode to ensure it is valid
  3. Filter out candidates based on years of experience per Skill
  4. Pick out candidates that have ALL skills in required skills (rows)
WITH  [
        {name: "Java", years_of_experience: 5},
        {name: "Spring Boot", years_of_experience: 1 } 
      ]  AS rows
UNWIND rows AS row
MATCH  (skill:SkillNode) WHERE skill.name = row.name
WITH  rows, row
// Validate the skills
MATCH (c:CandidateNode)-[r:KNOWS]->(s:SkillNode) 
    WHERE s.name  = row.name 
// Check if the years of experience is good
WITH c, r, s, rows, row 
    WHERE r.years_of_experience >= row.years_of_experience
// Check that candidate has ALL skills required 
WITH c, rows, collect(s) as candidateSkills 
    WHERE ALL(skill in rows WHERE skill.name in [c in candidateSkills|c.name]) 
RETURN c

Result:
╒════════════════╕
│"Candidate"     │
╞════════════════╡
│{"name":"Leo"}  │
├────────────────┤
│{"name":"Manos"}│
└────────────────┘

示例图: