0

那你怎么or条件and呢?下面的例子:

START user = node({id})
MATCH
(user)-[:follows]->(followed),
(follower)-[:follows]->(user)
RETURN user, followed, follower

我想得到的是:user,无论是否有人关注她或她是否关注任何人。全部followers,如果有的话。如果有的followed话。

上面的查询就像一个and. 如果 ifuser没有关注任何人,或者没有人关注用户,则不返回任何内容。


这是我尝试过的其他方法,但出现语法错误:

start a = node(40663) 
with a, a as b 
match (b)-[:follows]->(c) 
with b, a as d 
(e)-[:follows]->(d) 
return a, c, e;

错误:

SyntaxException: string matching regex `$' expected but `(' found

Think we should have better error message here? Help us by sending this query to cypher@neo4j.org.

Thank you, the Neo4j Team.

"start a = node(40663) with a, a as b match (b)-[:follows]->(c) with b, a as d (e)-[:follows]->(d) return a, c, e"
                                                                               ^

不管这个错误如何,减少的查询(只有一个with)返回零结果,所以这似乎也不是这样做的方法。

4

3 回答 3

1

你可以做:

START user = node({id})
MATCH
p1 = (user)-[:follows]->(followed),
p2 = (follower)-[:follows]->(user)
RETURN user, followed, follower

或者:

START user = node({id})
MATCH (user)-[:follows]->(f)
WITH user, collect(f) as followed 
MATCH (f)-[:follows]->(user)
RETURN user, followed, collect(f) as follower
于 2013-10-10T11:25:36.047 回答
0

好的,我可以使用以下方法解决这个问题:

start a = node(40663)
match (a)-[?:follows]->(b), (c)-[?:follows]->(a) 
return a, b, c;

但是,如果有更好的方法,请不要犹豫!

于 2013-10-05T15:52:43.777 回答
0

匹配 (c)<-[?:follows]-(a)-[?:follows]->(b) 也应该有效

编辑:或者

START user = node({id})
MATCH user--m 
WHERE user-[:follows]->m 
OR user<-[:followed]-m 
RETURN user  ,m
于 2013-10-07T11:51:13.927 回答