This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Comment

Looking at the console, it looks like the data you added made both sides 7->8 and 8->7, whereas in my User object the User friend property is Direction.BOTH, so when I set a friend by calling the addFriend method in User, is will set one to be a friend of the other, and since Direction = BOTH it should automatically do 7->8 and 8->7, but my code only set 7->8

Will

match sam-[:FRIEND*2]->friendsOfFriends

only return friendsOfFriends 2 levels down, or will it also include 1 level down from SAM? Although the second part of the match would remove those 1 level down anyway. I will try that out in my @Query and let you know how it goes.

Comment

Bummer, changing the query with yours still produces the exact same results which is not correct. For instance I have a user Cathy, who is friends with everyone. If I go into a user Mark, which only has Cathy as a friend, then the query should return all of Cathy's Friends for Mark, but I get zero results. If I go to a user John who has one friend Tom. Tom has three friends John, Cathy and Mike. When I query for John's friends of friends I correctly get Cathy and Mike as results back.

Comment

So Cathy is friends with everyone. Meaning cathy.addFriend() got passed all the other users one at a time, not like tom.addFriend(cathy). but cathy.addFriend(tom) etc.

So if those other users are friends only with Cathy and no others, then the query will return all of Cathy's friends for that user, which is what I would expect. However, if the other user is friends with Cathy and at least one more user, then I see none of Cathy's friends. So for example Tom is friends with Cathy and Bill only. Cathy is friends with Bill, Tom and 6 others. I would expect to see Tom's friends of friends to be those 6 others, but instead I get no results.

Hope that helps clarify. So somehow by having anyone else as friends also will negate Cathy's friends from being friends of friends.

Comment

"2) everyone who is 2 degrees out from a user but not a friend already?"

Exactly, what you thought.

But when I run that query against my data, but that is not what I am getting when I run that query. It only works as long as the start User only has one friend. If it has two friends then nothing will ever get returned from the query. That is a bug, problem.

So I have a User A who has one friend C, I also have a User B who is friends with C and D. Now C is friends with A, B, D, E, F, G, H, I, J.

You would expect running the query with A you'd get back, B, D, E, F, G, H, I, J and that is exactly what I get back.
You would expect running the query with B you'd get back A, E, F, G, H, I, J. Except, I get back nothing. 0 results back. And I figured it is because B has two friends instead of just one. That is what is happening in my database when I run that query. Could it be because I am running Neo4J Embedded?

It is just frustrating because we both know that that query as written is correct and we should see the results we are expecting. But when it doesn't I just scratch my head.

So, the query is the same as you had, in essence. I've added distinct results and used multi-step relationship match. I can't tell you what the problem was, but this version works. Also, it works with both unidirectional and bidirectional relationships.