如何将neo4j节点的属性存储为数组? [英] How to store properties of a neo4j node as an array?
问题描述
我正在使用neo4j进行HR分析项目,遇到一个复杂的查询(我对cypher也很陌生).基本上,我列出了具有一些功能的员工列表,例如位置,技能集,教育程度以及具有位置,所需技能的职位.我查看位置(员工的位置和位置的位置)是否匹配,并将该分数设置为1(否则为0).如果我只有一个空缺职位,则查询工作正常.但是,随着位置的增加,变量将被最后一个位置的最后一个值覆盖.我可以想象将节点属性放在数组中,但是似乎密码没有(不推荐使用).
I am working on an HR analytics projects using neo4j and I encountered a complicated query (I am also very new to cypher). Basically, I have a list of employee with some features like location, skill set, education and positions with location, skills required. I look if location (employee’s location and position’s location) matches and set that score to 1 (0 otherwise). If I have only one open position, the query works fine. However, with more positions the variable gets overwritten with last value of last position. I would imagine putting the node properties in an array but doesn’t seem that cypher has that (deprecated).
https://neo4j.com/docs/rest-docs/current/#rest-api-property-values
这是我使用的查询,如果您能帮助我解决问题,将不胜感激.最终目标是在给定职位上为每位员工提供一个分数,并用得分最高的员工填补该职位.在cypher上甚至有可能吗? 非常感谢
This is the query that I use and I would be grateful if you can help me resolve the issue. Final goal is to have a score for every employee per a given position and fill the position with the employee with highest score. Is this even possible on cypher?? Thanks a lot
MATCH
(e:Employee)-[r:FUTURE_POSITION]-> (p:Position {open_status:1}),
(e)-[h:HAS_DEGREE]-> (d:Degree),
(e)-[s:HAS_SKILL]-> (n:Personal_Skill)
WITH r, e,p,d,n,
CASE WHEN p.position_state = e.home_state THEN 1 ELSE 0 END AS SameStateScore,
CASE WHEN p.position_city = e.home_city THEN 1 ELSE 0 END AS SameCityScore,
CASE WHEN d.name = "College Degree" THEN 1 ELSE 0 END AS HasCollegeDegree,
CASE WHEN n.name = "Management" THEN 1 ELSE 0 END AS HasRequiredSkill
SET e.score = SameStateScore + SameCityScore + HasCollegeDegree + HasRequiredSkill
RETURN DISTINCT e.name,p.name, SameStateScore,SameCityScore,HasCollegeDegree,MAX(HasRequiredSkill) AS HasRequiredSkill, e.score
ORDER BY e.score DESC
推荐答案
您在问题中使用的链接( HTTP API .
The link you used in your question (https://neo4j.com/docs/rest-docs/current/#rest-api-property-values) is for the deprecated legacy REST API. If you want to make HTTP requests to execute Cypher, you can use the new HTTP API instead.
为了每个职位都有单独的员工分数,您不应该将分数存储在Employee
节点中,而应该存储在FUTURE_POSITION
关系中-因为每个职位都有单独的关系.因此,只需使用r.score
而不是e.score
:
In order to have a separate employee score per position, you should not be storing the score in the Employee
node, but in the FUTURE_POSITION
relationship -- since there is a separate relationship per position. So, just use r.score
instead of e.score
:
MATCH
(e:Employee)-[r:FUTURE_POSITION]->(p:Position {open_status:1}),
(e)-[:HAS_DEGREE]-> (d:Degree),
(e)-[:HAS_SKILL]-> (n:Personal_Skill)
WITH r, e, p,
CASE WHEN p.position_state = e.home_state THEN 1 ELSE 0 END AS SameStateScore,
CASE WHEN p.position_city = e.home_city THEN 1 ELSE 0 END AS SameCityScore,
CASE WHEN d.name = "College Degree" THEN 1 ELSE 0 END AS HasCollegeDegree,
CASE WHEN n.name = "Management" THEN 1 ELSE 0 END AS HasRequiredSkill
SET r.score = SameStateScore + SameCityScore + HasCollegeDegree + HasRequiredSkill
RETURN DISTINCT
e.name, p.name, SameStateScore, SameCityScore, HasCollegeDegree,
MAX(HasRequiredSkill) AS HasRequiredSkill, r.score
ORDER BY r.score DESC
此外,可能不需要DISTINCT
选项,因为聚合函数(如MAX
)已经确保同一结果行中的非聚合值集是不同的.
Also, the DISTINCT
option may not be needed, as aggregation functions (like MAX
) already make sure the set of non-aggregated values in the same result row are distinct.
这篇关于如何将neo4j节点的属性存储为数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!