如何优化此密码查询?它比使用 Gremlin 的类似查询慢 3-4 倍。
START movie=node:vertices(movieId="100")
MATCH genera1<--movie<--()-[ratedRel:rated]->anotherMovie-->genera1
WHERE ratedRel.stars > 3
RETURN anotherMovie.title as title, anotherMovie.movieId as id,
genera1.genera as genera,
COUNT(anotherMovie) as count ORDER BY count(anotherMovie) DESC LIMIT 20;
我只是想检索评分超过 3 星且与 START 节点具有相同属的电影:http: //markorodriguez.files.wordpress.com/2011/09/movielens-schema.png? w=350
我在控制台中运行查询,我使用的是 Neo4j 1.9
Gremlin 查询:
m = [:];
x = [] as Set;
v = g.v(node_id);
v.out('hasGenera').aggregate(x).back(2).inE('rated').
filter{it.getProperty('stars') > 3}.outV.outE('rated').
filter{it.getProperty('stars') > 3}.
inV.filter{it != v}.
filter{it.out('hasGenera').toSet().equals(x)}.
groupCount(m){\"${it.id}:${it.title.replaceAll(',',' ')}\"}.iterate();
m.sort{a,b -> b.value <=> a.value}[0..24];