简体   繁体   English

neo4j 找到所有发布我喜欢的东西的朋友

[英]neo4j find all friends who posted something I liked

I want to find all the friends that posted something I liked.我想找到所有发布我喜欢的东西的朋友。 Why does this query return no rows but each clause by themselves returns something?为什么这个查询不返回任何行但每个子句本身都返回一些东西?

 match (start:Person)-[:LIKES]->(post:Post), (start)-[:FRIEND]->(person: Person), (person)-[:POSTED]->(post) return start, post, person

profile01 简介02

Thanks for the query plans.感谢您的查询计划。

We can see that the rows drop to zero on the expansion of (start)-[:FRIEND]->(person) , so one of two things is happening: either:FRIEND isn't the actual relationship type (probably an issue of mismatched cases), or more likely, all the:FRIEND relationships present are in the opposite direction, incoming to the start node instead of outgoing.我们可以看到,在(start)-[:FRIEND]->(person)的扩展中,行数下降到零,因此发生了以下两种情况之一:要么:FRIEND 不是实际的关系类型(可能是不匹配的情况),或者更有可能的是,所有存在的:FRIEND 关系都是相反的方向,传入到起始节点而不是传出。

For social graphs like these, since they're both:Person nodes, there isn't a way to tell which direction the relationship was created in, and when you query, the direction shouldn't matter, all that should matter is that a:FRIEND relationship exists.对于像这样的社交图,因为它们都是:Person 节点,所以无法判断关系是在哪个方向创建的,当您查询时,方向不重要,重要的是:FRIEND 关系存在。

Try removing the direction from the pattern here: (start)-[:FRIEND]-(person: Person) .尝试从此处的模式中删除方向: (start)-[:FRIEND]-(person: Person) Provided your relationship type is correct, that should get you the right results.如果你的关系类型是正确的,那应该会给你带来正确的结果。

For simplicity, I would also combine the 3 patterns into a single long pattern.为简单起见,我还将这 3 个模式组合成一个长模式。 Doing this will ensure that it doesn't pull extra patterns that don't fit later patterns (get retrieved, then filtered out later).这样做将确保它不会提取不适合以后模式的额外模式(被检索,然后稍后过滤掉)。 Here is what that Cypher would look like:这是 Cypher 的样子:

MATCH (start:Person)-[:LIKES]->(post:Post)<-[:POSTED]-(person: Person)
WHERE (start)-[:FRIEND]-(person)
RETURN start, post, person

I would start by我会从

MATCH (me:Person)-[:FRIEND]-(friend:Person)-[:POSTED]->(post:Post)<-[:LIKES]-(me)
RETURN DISTINCT friend

To get the (friend:Person) nodes获取 (friend:Person) 节点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM