Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-04-2022 09:17 PM - edited 08-05-2022 08:47 AM
Hi there, I have member and event node. I want to find out which event is paid the most attention by count with "register" and "bookmark" relationship so that I start from these query
Failed to invoke function `apoc.coll.sort`: Caused by: java.lang.ClassCastException: class java.util.HashMap cannot be cast to class java.lang.Comparable (java.util.HashMap and java.lang.Comparable are in module java.base of loader 'bootstrap')
cloud you help improve this query ? or better solution ?
Solved! Go to Solution.
08-05-2022 03:19 PM
Give this a try. It calculates the count of the registered members. If the number is zero, then it calculates the number of bookmarked members. It then sorts the event count.
match (e:Event)
optional Match (m:Member)-[:REGISTERED]->(e:Event)
with e, count(m) as countRegistered
call {
with countRegistered, e
with countRegistered, e
where countRegistered = 0
optional match (n:Member)-[:BOOKMARKED]->(e)
return count(n) as countBookmarked
}
return e, countRegistered + countBookmarked as eventCount
order by eventCount desc
08-04-2022 09:42 PM
Try this:
Match p1=(a:Member)-[:REGISTER]->(e1:Event)
with nodes(p1) as n1, relationships(p1) as rel
unwind n1 as n2
unwind rel as rels
Match p2=(b:Member)-[:BOOKMARK]->(c:Event)
where id(b) in id(n2) and id(c)in id(n2)
return p2
This should show you the Member and Event nodes with [:REGISTER] and [:BOOKMARK] relationships
08-05-2022 02:18 AM
It sounds like 'find out which event is paid the most attention' means determining how many members registered and bookmarked each event, so you can determine which is more active. If that is what you are looking for, try the following:
Match (m:Member)-[:REGISTER]->(e:Event)
with e, count(*) as noOfMemberRegistrations, collect(m.name) as registeredMembers
Match (m:Member)-[:BOOKMARK]->(e)
with e, noOfMemberRegistrations, registeredMembers, count(*) as noOfMemberBookmarks, collect(m.name) as bookmarkedMembers
return e, noOfMemberRegistrations, registeredMembers, noOfMemberBookmarks, bookmarkedMembers, noOfMemberRegistrations + noOfMemberBookmarks as totalEventMembers
order by totalEventMembers desc
The query counts the total number of member registrations and bookmarks for each event, as well as collecting the names of the members that registered and bookmarked the event. It then lists the events by total count in descending order so you can see the events with the most 'attention.'
08-05-2022 08:44 AM - edited 08-05-2022 08:49 AM
@glilienfield
ah I figure out, I just want only event node which has most attention (count by "REGISTER" or "BOOKMARK" if member have both just count "REGISTER") cloud you help improve this query ? or better solution ?
I try apoc.coll.sort that throw errors
Failed to invoke function `apoc.coll.sort`: Caused by: java.lang.ClassCastException: class java.util.HashMap cannot be cast to class java.lang.Comparable (java.util.HashMap and java.lang.Comparable are in module java.base of loader 'bootstrap')
08-05-2022 03:19 PM
Give this a try. It calculates the count of the registered members. If the number is zero, then it calculates the number of bookmarked members. It then sorts the event count.
match (e:Event)
optional Match (m:Member)-[:REGISTERED]->(e:Event)
with e, count(m) as countRegistered
call {
with countRegistered, e
with countRegistered, e
where countRegistered = 0
optional match (n:Member)-[:BOOKMARKED]->(e)
return count(n) as countBookmarked
}
return e, countRegistered + countBookmarked as eventCount
order by eventCount desc
All the sessions of the conference are now available online