3

I'm using neo4j, storing a simple "content has-many tags" data structure. I'd like to find out "what tags co-exist with what other tags the most?"

I've got around 500K content-to-tag relationships, so unfortunately, that works out to 0.5M^2 posible coexist relationships, and then you need to count how many each type of relationship happens! Or do you? Am I doing this the long way?

It never seems to return, and my CPU is pegged out for quite some time now.

final ExecutionResult result = engine.execute(
 "START metag=node(*)\n"
 + "MATCH metag<-[:HAS_TAG]-content-[:HAS_TAG]->othertag\n"
 + "WHERE metag.name>othertag.name\n"
 + "RETURN metag.name, othertag.name, count(content)\n"
 + "ORDER BY count(content) DESC");
for (Map<String, Object> row : result) {
 System.out.println(row.get("metag.name") + "\t" + row.get("othertag.name") + "\t" + row.get("count(content)"));
}
4

1 回答 1

1

您应该尝试减少绑定点以加快遍历速度。我假设你的图表总是有比内容更多的标签,所以你应该把内容作为你的界限。就像是

start 
     content = node:node_auto_index(' type:"CONTENT" ')
match
     metatag<-[:HAS_CONTENT]-content-[:HAS_CONTENT]->othertag
where 
     metatag<>othertag
return 
     metatag.name, othertag.name, count(content)  
于 2013-04-12T01:48:42.960 回答