当我在c_from
和c_to
上有一个匹配项时,以下请求通常可以使用:
MATCH (u:User {uid: $userId})
WITH u UNWIND $statements as statement
WITH u, statement
UNWIND statement.conceptsRelations as conceptsRelation
MATCH (c_from:Concept{name: conceptsRelation.from})
MATCH (c_to:Concept{name: conceptsRelation.to})
CREATE (c_from)-[:TO {context:conceptsRelation.context,statement:conceptsRelation.statement,user:u.uid,timestamp:conceptsRelation.timestamp, uid:apoc.create.uuid(), gapscan:conceptsRelation.gapscan, weight: conceptsRelation.weight}]->(c_to)
WITH u, statement
UNWIND statement.mentionsRelations as mentionsRelation
MATCH (m_from:Concept{name: mentionsRelation.from})
MATCH (m_to:Concept{name: mentionsRelation.to}) return m_from, m_to
但是,一旦我没有任何匹配项,查询的最后一部分(最后一个UNWIND
)就不会执行。我通过删除第二个UNWIND
进行了检查,然后第三个再次工作。如:
MATCH (u:User {uid: $userId})
WITH u UNWIND $statements as statement
WITH u, statement
UNWIND statement.mentionsRelations as mentionsRelation
MATCH (m_from:Concept{name: mentionsRelation.from})
MATCH (m_to:Concept{name: mentionsRelation.to}) return m_from, m_to
以防万一,我的参数是:
{
"userId": "15229100-b20e-11e3-80d3-6150cb20a1b9",
"contextNames": [
{
"uid": "af8debb0-1f71-11e9-a572-691cc47b060f",
"name": "dsfasdf"
}
],
"statements": [
{
"text": "@submit desire",
"concepts": [
"desire"
],
"mentions": [
"@submit"
],
"timestamp": 15482915128250000,
"name": "#desire @@submit ",
"uid": "2bd1f170-1f73-11e9-a508-0d8a16ad5cf6",
"uniqueconcepts": [
"desire"
],
"conceptsRelations": [],
"mentionsRelations": [
{
"from": "desire",
"to": "@submit",
"context": "af8debb0-1f71-11e9-a572-691cc47b060f",
"statement": "2bd1f170-1f73-11e9-a508-0d8a16ad5cf6",
"user": "15229100-b20e-11e3-80d3-6150cb20a1b9",
"timestamp": 15482915128250000,
"uid": "apoc.create.uuid()",
"gapscan": "1",
"weight": 3
}
],
"uniquementions": [
"@submit"
]
}
],
"timestamp": 15482915128250000
}
这似乎是一种奇怪的不合逻辑的行为。知道为什么会出现吗?谢谢!
答案 0 :(得分:0)
UNWIND的用途是将列表变成行 如果列表为空,则行数为零。
如果元素为空,则可以将其添加到列表中:
UNWIND case when size(list) = 0 then [null] else list end
或
UNWIND list + null
然后跳过第二部分中的特殊值。