Question about cypher query counting results

querying
cypher

(Claudiofrancesconi) #1

hi
i am using neo4j desktop for mac version 1.1.1.2
with neo browser 3.2.13
i have a simple graph with USERS and PAGES and relationship called LIKES
USERS likes different pages
so there are different USERS liking same PAGES.

i would love to make a query with cypher to show me only the PAGES liked by more than x USERS.
and i did it with this:

MATCH ()-[r:LIKES]->(n)
WITH n, count(r) as conto
WHERE conto > 5
RETURN n;

the problem is that like this i can only see pages.
what if i want to see pages and users and relationships?

thank you for the support


(Andrew Bowman) #2

A better approach is to use the size() function on the pattern, which will use the degree of the relationship type for each node instead of actually expanding/traversing the relationships.

Once you use this to filter to the pages in question (and you should be using labels for your query), then you can actually do the work of expanding out and returning the interested paths for display. Assuming your labels are User and Page:

MATCH (n:Page)
WHERE size(()-[:LIKES]->(n)) > 5
MATCH p = ()-[:LIKES]->(n) 
RETURN p;

(Claudiofrancesconi) #3

thank you
that was really helpful