Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j Cypher query empty collect使整个结果为空_Neo4j_Cypher_Graph Databases - Fatal编程技术网

Neo4j Cypher query empty collect使整个结果为空

Neo4j Cypher query empty collect使整个结果为空,neo4j,cypher,graph-databases,Neo4j,Cypher,Graph Databases,我一直面临wierd问题,我试图从我构建的neo4j图中获取数据 MATCH (u1:User {user_id: 4})-[:FOLLOWS]->(u2:User)-[]->(r1:Rest{city_id: 1}) WITH COLLECT ({ REST: r1.res_id}) as rows MATCH (u1:User {user_id: 4})-[rel]->(r2:Rest{city_id: 1}) WHERE NOT (u1:User {user_id: 4}

我一直面临wierd问题,我试图从我构建的neo4j图中获取数据

MATCH (u1:User {user_id: 4})-[:FOLLOWS]->(u2:User)-[]->(r1:Rest{city_id: 1})
WITH COLLECT ({ REST: r1.res_id}) as rows
MATCH (u1:User {user_id: 4})-[rel]->(r2:Rest{city_id: 1})
WHERE NOT (u1:User {user_id: 4})-[rel : BEEN_THERE | ADD_REVIEW]->(r2:Rest{city_id: 1})
WITH rows + COLLECT ({ REST: r2.res_id}) AS allrows
UNWIND allrows as row 
RETURN row.REST as RESTAURANT_ID, count(row.REST) as COUNT
ORDER BY COUNT desc
LIMIT 15;

但是,当COLLECT({REST:r2.res_id})的结果为空时,整个结果将变为空。此外,查询无法从第一次匹配中识别行并返回未定义的
。请让我知道。谢谢

如果模式与任何路径都不匹配,则结果将确实为空

您必须将
匹配
拆分为2,并将第二个
设置为可选
,或者在实际情况中,反复停止匹配相同的
u1
节点:

MATCH (u1:User {user_id: 4})
OPTIONAL MATCH (u1)-[:FOLLOWS]->(:User)-->(r1:Rest {city_id: 1})
WITH u1, collect({ REST: r1.res_id }) AS rows
OPTIONAL MATCH (u1)-->(r2:Rest {city_id: 1})
WHERE NOT (u1)-[:BEEN_THERE | ADD_REVIEW]->(r2)
WITH rows + collect({ REST: r2.res_id }) AS allrows
UNWIND allrows as row 
RETURN row.REST AS RESTAURANT_ID, count(row.REST) AS COUNT
ORDER BY COUNT desc
LIMIT 15

我不确定第一个
可选匹配
(您只提到第二个
collect
是一个拦截器),但如果您希望两个模式的聚合,其中每个模式都可以为空,那就来吧。

非常感谢您的回答!它工作正常。@AditKaushal请毫不犹豫地回答。