Hi Alx,
Most probably because your data/graph simply not fullful your total cypher
statement, Remeber that your are matchning a pattern and you start with
limiting it to users that has a uid property. For example the graph data
below returns a resultset for each individually MATCH queries, however once
chained, like your query, it fails to match that pattern. That is becuse
there is no User that has uid property and other nodes that are connected
via the LOCATED_IN (the cities they are living in) relationship, thus your
query will return nil in the end.
So with this graph data:
CREATE (Pontus:User { uid:'Pontus Lundin',name:'Pontus Lundin'
}),(John:User { uid: 'John Hellberg',name:'John Hellberg' }),(Jack:User {
uid: 'Jack Hellberg',name:'Jack Hellberg' }),(Nisse:User { name: 'Nisse
Larsson' }),(Kalle:User { name: 'Kalle Johansson' }),(Johan:User {
name:'Johan Davidsson' }),(Ronny:User { name: 'Ronny Stork' }),(Micke:User
{ name: 'Mikael Jansson' }),(Anna:User { name: 'Anna Karlsson',
sex:'female' }),(Sandra:User { name: 'Sandra Johansson', sex:'female'
}),(Fredrik:User { name:'Fredrik Hansson' }),(Gothenburg:Location {
name:'Gothenburg',dailyhits:1000000 }),(Stockholm:Location {
name:'Stockholm',dailyhits:300000 }),(Sundsvall:Location {
name:'Sundsvall',dailyhits:6000 }),(Malmo:Location {
name:'Malmö',dailyhits:20000 }),
(Pontus)-[:LOCATED_IN]->(Gothenburg),
(Ronny)-[:LOCATED_IN]->(Sundsvall),
(Sandra)-[:LOCATED_IN]->(Sundsvall),
(Pontus)-[:TEXTED]->(Sandra),
(Pontus)-[:TEXTED]->(Fredrik),
(Jack)-[:LOCATED_IN]->(Malmo),
(John)-[:LOCATED_IN]->(Stockholm),
(Jack)-[:TEXTED]->(Pontus);
This pattern will return data:
MATCH (n:User)
WHERE HAS (n.uid)
return n;
As well as:
MATCH (n)-[:LOCATED_IN]->()<-[:LOCATED_IN]-(m),(n)-[:TEXTED]-(k)
WITH COLLECT(DISTINCT m.name) AS users1, COLLECT(DISTINCT k.name) AS users2
RETURN users1+ users2
But not this chained Cypher query which return empty
MATCH (n:User)
WHERE HAS (n.uid)
MATCH (n)-[:LOCATED_IN]->()<-[:LOCATED_IN]-(m),(n)-[:TEXTED]-(k)
WITH COLLECT(DISTINCT m.name) AS users1, COLLECT(DISTINCT k.name) AS users2
RETURN users1+ users2
However if your data has connection that fullfulls your query then it works
(now a User with uid lives in the same city as another node), like:
CREATE (Pontus:User { uid:'Pontus Lundin',name:'Pontus Lundin'
}),(John:User { uid: 'John Hellberg',name:'John Hellberg' }),(Jack:User {
uid: 'Jack Hellberg',name:'Jack Hellberg' }),(Nisse:User { name: 'Nisse
Larsson' }),(Kalle:User { name: 'Kalle Johansson' }),(Johan:User {
name:'Johan Davidsson' }),(Ronny:User { name: 'Ronny Stork' }),(Micke:User
{ name: 'Mikael Jansson' }),(Anna:User { name: 'Anna Karlsson',
sex:'female' }),(Sandra:User { name: 'Sandra Johansson', sex:'female'
}),(Fredrik:User { name:'Fredrik Hansson' }),(Gothenburg:Location {
name:'Gothenburg',dailyhits:1000000 }),(Stockholm:Location {
name:'Stockholm',dailyhits:300000 }),(Sundsvall:Location {
name:'Sundsvall',dailyhits:6000 }),(Malmo:Location {
name:'Malmö',dailyhits:20000 }),
(Pontus)-[:LOCATED_IN]->(Sundsvall),
(Ronny)-[:LOCATED_IN]->(Sundsvall),
(Sandra)-[:LOCATED_IN]->(Sundsvall),
(Pontus)-[:TEXTED]->(Sandra),
(Pontus)-[:TEXTED]->(Fredrik),
(Jack)-[:LOCATED_IN]->(Malmo),
(John)-[:LOCATED_IN]->(Stockholm),
(Jack)-[:TEXTED]->(Pontus);
If you still want to return *something* (if it makes sense for your result)
event though the "match fails" you can use the OPTIONAL match like the one
below:
MATCH (n:User)
WHERE HAS (n.uid)
OPTIONAL
MATCH (n)-[:LOCATED_IN]->()<-[:LOCATED_IN]-(m)
WITH n,m
MATCH (n)-[:TEXTED]-(k)
WITH COLLECT(DISTINCT m.name) AS users1, COLLECT(DISTINCT k.name) AS users2
RETURN users1+ users2
Den söndagen den 20:e april 2014 kl. 02:00:33 UTC+2 skrev Alx:
>
> I have the following cypher query:
>
> MATCH (n:User) WHERE HAS(n.uid) MATCH
> (n)-[:LOCATED_IN]->()<-[:LOCATED_IN]-(m), (n)-[:TEXTED]-(k) WITH COLLECT
> (DISTINCT m.name) AS users1, COLLECT( DISTINCT k.name )
> AS users2 RETURN users1+ users2
>
> But it returns me no result. It just returns a title "users1+ users2". I
> know that there are results in the query because I executed them
> individually.
>
> My goal is to collect all the results from individual matches and then
> count the distinct names. Thanks for the help in advance.
>
>
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.