I have a Neo4j database with User, Content, and Topic nodes. I want to calculate the proportion of content consumed by a given user for a given topic.
MATCH (u:User)-[:CONSUMED]->(c:Content)<-[:CONTAINS]-(t:Topic)
WHERE ID(u) = 11158 AND ID(t) = 19853
MATCH (c1:Content)<-[:CONTAINS]-(z)
RETURN toFloat(COUNT(DISTINCT(c))) / toFloat(COUNT(DISTINCT(c1)))
Two things strike me as really ugly here:
- Firstly, is
COUNT(DISTINCT())a hack to get round the fact that the twoMATCHqueries cross-join? - Float division is ugly.
The second is something I can live with, but the first seems inefficient; is there a better way to express this idea?