将网址查询转换为节点

时间:2019-03-30 12:37:05

标签: neo4j cypher neo4j-apoc

我正在尝试将Url-String转换为带有密码的节点:

`https://e.whoopidoo.nl/x/plugin/?pName=edit_data&MIDRID=S7Y1Mv2fa2tobGz5P8fW0NzU4n8RUMjYwNIAAAA21&Z=-394462905&utm_source=DMdelivery&utm_medium=email&utm_content=ae9982saa&utm_campaign=aletter%202018"`

并使用

将其转换为数组
`split(apoc.data.url(u.url).query,"&") as urlArr`

结果数组:["pName=edit_data", "MIDRID=S7Y1Mv2fa2tobGz5P8fW0NzU4n_RrZGhsZmRJQAA67", "Z=-1006289928", "utm_source=DMdelivery", "utm_medium=email", "utm_content=ae9982saa", "utm_campaign=aletter 2018"]

请帮助您采取以下步骤:

  • 如何通过urlArrUNWINDFOREACH遍历apoc.function
  • 然后在循环split( arrValue, "=") as keyValue中使用每个值
  • 如何收集这些键值转换为该网址的(:urlQuery{ collectedKeyVals })

密码:

MATCH (u:Url)
WITH u, split(apoc.data.url(u.url).query,"&") as urlArr 
// UNWIND or FOREACH - urlArr?
// ... in loop ... split( arrValue, "=") as keyValue
// How to COLLECT efficiently ?
// MERGE or CREATE

2 个答案:

答案 0 :(得分:0)

  1. 使用List comprehension获取键值对列表
  2. 然后使用apoc.map.fromPairs函数从具有键值对的列表中获取地图
  3. 然后使用SET从地图上设置属性

WITH "https://e.whoopidoo.nl/x/plugin/?pName=edit_data&MIDRID=S7Y1Mv2fa2tobGz5P8fW0NzU4n8RUMjYwNIAAAA21&Z=-394462905&utm_source=DMdelivery&utm_medium=email&utm_content=ae9982saa&utm_campaign=aletter%202018" as url
WITH split(apoc.data.url(url).query,"&") as urlArr

// 1
WITH [n in urlArr | split(n, '=')] as keyValuePairs
// 2
WITH apoc.map.fromPairs(keyValuePairs) as keyValueMaps
// 3 
CREATE (U:urlQuery) SET U = keyValueMaps

RETURN U

答案 1 :(得分:0)

您可以在创建节点后使用UNWIND来通过apoc动态设置这些属性。

WITH split(apoc.data.url("https://e.whoopidoo.nl/x/plugin/?pName=edit_data&MIDRID=S7Y1Mv2fa2tobGz5P8fW0NzU4n8RUMjYwNIAAAA21&Z=-394462905&utm_source=DMdelivery&utm_medium=email&utm_content=ae9982saa&utm_campaign=aletter%202018").query,"&") as urlArr 
CREATE (N:urlQuery) 
WITH N,urlArr
UNWIND urlArr as urlValue 
CALL apoc.create.setProperty(N, split( urlValue, "=")[0], split( urlValue, "=")[1]) YIELD node
RETURN node