是否可以通过关系密码的属性进行迭代

是否可以通过关系密码的属性进行迭代

本文介绍了是否可以通过关系密码的属性进行迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与以下问题有关:如何将neo4j节点的属性存储为数组?我想遍历关系的一个属性,并检查该值的最大值,并分配新的node1和node2关系,并从池中删除node1并移至第二个.换句话说,就像在我之前的问题中一样,如何将给定员工分配给基于max(r.score)的给定职位,并转移到另一个为另一个职位拥有最大r.score的员工?谢谢

This is related to this question: How to store properties of a neo4j node as an array?I would like to iterate through a property of a relationship and check max of that value and assign a new relationship of node1 and node2 and delete node1 from the pool and move to the second one. In other words as in the context of my previous question, How to assign a given employee to a given position based max(r.score) and move to the other employee who has a maximum r.score for another position? Thanks

具有此基本查询可为具有最高r.score w.r.t职位的员工分配职位,并将其从候选人池中删除.但是,我必须手动将其运行到第二个位置.理想情况下,我需要一种检查长度(如果有)的长度,然后用max(r.score)填充位置,然后在所有位置填充后停止的东西.可能会返回聘用员工的报告...

Have this basic query to assign a position for the employee who has a maximum r.score w.r.t position and remove him from pool of candidates. However, I have to run this manually for the second position. Ideally I want something that checks length if available positions and then fills positions with max(r.score) and then stops when all positions are filled. may be returns a report of hired employees...

MATCH (e:Employee)-[r:FUTURE_POSITION]->(p:Position)
WITH MAX(r.score) as s
MATCH (e)-[r]->(p) WHERE r.score = s
CREATE (e)-[r2:YOUAREHIRED]->(p)
DELETE r
RETURN e.name, s

推荐答案

此查询可能对您有用:

MATCH (:Employee)-[r:FUTURE_POSITION]->(p:Position)
WITH p, COLLECT(r) AS rs
WITH p, REDUCE(t = rs[0], x IN rs[1..] |
  CASE WHEN x.score > t.score THEN x ELSE t END) AS maxR
WITH p, maxR, maxR.score AS maxScore, STARTNODE(maxR) AS e
CREATE (e)-[:YOUAREHIRED]->(p)
DELETE maxR
RETURN p, e.name AS name, maxScore;

  • 第一个WITH子句收集每个p的所有FUTURE_POSITION关系.
  • 第二个WITH子句为每个p获取与最大score的关系.
  • 第三个WITH子句提取后续子句所需的变量.
  • CREATE子句在e(给定p的得分最高的员工)和p之间创建YOUAREHIRED关系.
  • DELETE子句删除ep之间的FUTURE_POSITION关系.
  • RETURN子句返回每个p,以及刚为p雇用的员工的name和他的分数maxScore.
    • The first WITH clause collects all the FUTURE_POSITION relationships for each p.
    • The second WITH clause obtains, for each p, the relationship with the maximum score.
    • The third WITH clause extracts the variables needed by subsequent clauses.
    • The CREATE clause creates the YOUAREHIRED relationship between e (the employee with the highest score for a given p) and p.
    • The DELETE clause deletes the FUTURE_POSITION relationship between e and p.
    • The RETURN clause returns each p, along with and the name of the employee who was just hired for p, and his score, maxScore.
    • [更新]

      如果要删除每个获得YOUAREHIRED关系的p节点的 all FUTURE_POSITION关系,则可以使用以下稍微不同的查询:

      If you want to delete all FUTURE_POSITION relationships of each p node that gets a YOUAREHIRED relationship, you can use this slightly different query:

      MATCH (:Employee)-[r:FUTURE_POSITION]->(p:Position)
      WITH p, COLLECT(r) AS rs
      WITH p, rs, REDUCE(t = rs[0], x IN rs[1..] |
        CASE WHEN x.score > t.score THEN x ELSE t END) AS maxR
      WITH p, rs, maxR.score AS maxScore, STARTNODE(maxR) AS e
      CREATE (e)-[:YOUAREHIRED]->(p)
      FOREACH(x IN rs | DELETE x)
      RETURN p, e.name AS name, maxScore;
      

      这篇关于是否可以通过关系密码的属性进行迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 14:32