Thanks for your suggestion Michael.
However, I managed to do the trick with this query:
MATCH (person:Person)
WITH person
OPTIONAL MATCH (person)-[:KNOWS]-(p1:Person)
WITH person, COALESCE(COLLECT(p1),[]) AS p1s
WITH person, CASE p1s WHEN [] THEN [NULL] ELSE p1s END AS p1s
UNWIND p1s AS p1
you can also use the path directly then you can specify a minimum length too
and you should use a newer version of Neo4j.
MATCH (person:Person)
OPTIONAL MATCH (person)-[:KNOWS]-(p:Person)
WITH person, count(p) as f1
OPTIONAL MATCH (person)-[:KNOWS*2]-(f2:Person)
WITH count(distinct f2) as f2,
shortestPath returns the right results.
Without it, wrong results.
--
You received this message because you are subscribed to the Google Groups
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to neo4j+unsubscr...@googlegroups.com.
For more
Yes, but it would never be counted as a friend of friend.
On Wednesday, March 16, 2016 at 12:28:44 AM UTC+1, Michael Hunger wrote:
>
> your shortest-path doesn't imply that it's not the same person.
>
> Robert would also be counted as direct friend.
>
> On Wed, Mar 16, 2016 at 12:25 AM, Michael
Yes, but it would never be counted as a friend of friend.
> Le 16 mars 2016 à 00:28, Michael Hunger a
> écrit :
>
> your shortest-path doesn't imply that it's not the same person.
>
> Robert would also be counted as direct friend.
>
> On Wed, Mar 16, 2016
your shortest-path doesn't imply that it's not the same person.
Robert would also be counted as direct friend.
On Wed, Mar 16, 2016 at 12:25 AM, Michael Azerhad wrote:
> Hi Michael,
>
> I think your query would result wrong results.
>
> Michael - *KNOWS* - Julia -
Hi Michael,
I think your query would result wrong results.
Michael - *KNOWS* - Julia - *KNOWS* - Robert - *KNOWS* - Michael (same
Michael as previous one)
It would consider Robert as a friend's friend for Michael (Michael - Julia
- Robert).
However, it is his direct friend ... (Robert -
try this:
MATCH (person:Person)
OPTIONAL MATCH (person)-[:KNOWS]-(f1:Person)-[:KNOWS]-(f2:Person)-[:KNOWS]-(
f3:Person)
WITH person, count(distinct f1) as f1, count(distinct f2) as f2,count(distinct
f3) as f3
RETURN person._firstName + " " + person._lastName, f1, f2, f3
alternatively
MATCH