1
votes

I've this cypher query:

MATCH (p:Person)-->(s:Startup)
WHERE p.name =~ '(?i).*something.*' OR p.description =~ '(?i).*something.*' OR s.name =~ '(?i).*something.*'
RETURN DISTINCT p, collect(DISTINCT s)

This returns:

+--------+------------+
|   p    | collect(s) |
+--------+------------+
|   1    |     1      |
+--------+------------+

where I was expecting:

+--------+------------+
|   p    | collect(s) |
+--------+------------+
|   1    |     1, 2   |
+--------+------------+

When someone search for a name, it returns me all the matched people and related startups with this criteria, but I want that it returns me all the matched people and always all the relationships between the 2 nodes.

(i.e. if I search for a startup name, I want that the result is the list of people and the startups in relationship, not only the people and the matched startup)

I hope I've explained well the issue.

My wish is to get the results in one query.

1
can you give an example of the output you're looking for?Eve Freeman
I want to search startups or people that have "Pork" in some property. The result is that a startup exist and it returns the person related, but only that startup. My need is to have all the startups of that person, without doing any other query, if is it possible.bepi_roggiuzza

1 Answers

3
votes

I think you're looking for something like this, where you do the first query to find any person related to your query, and then do a WITH and continue the query using that person:

MATCH (p:Person)-->(s:Startup)
WHERE p.name =~ '(?i).*something.*' OR p.description =~ '(?i).*something.*' OR s.name =~ '(?i).*something.*'
WITH DISTINCT p
MATCH (p)-->(s:Startup)
RETURN DISTINCT p, collect(DISTINCT s)