0

如何优化此密码查询?它比使用 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];
4

1 回答 1

0
START movie=node:vertices(movieId="100") 
MATCH movie-->genera1<-anotherMovie<-[ratedRel:rated]-user
WHERE ratedRel.stars > 3 
RETURN anotherMovie.title as title, anotherMovie.movieId as id, genera1.genera as genera, 
COUNT(ratedRel) as cnt ORDER BY cnt DESC LIMIT 20;

更新: 根据您的 gremlin 查询,您可以试试这个吗?

START movie=node:vertices(movieId="100") 
MATCH movie-[:hasGenera]->genera1<-[:hasGenera]-anotherMovie<-[ratedRel:rated]-user
WITH anotherMovie,count(ratedRel) as allVotes, sum(ratedRel) as allStars,genera1
WHERE allStars/allVotes>3 
RETURN anotherMovie.title as title, anotherMovie.movieId as id, genera1.genera as genera, 
allStars ORDER BY allStars DESC LIMIT 20;

关键是在路径中尽可能多地定义元素(在这种情况下,我们错过了 rels 名称)并省略了user我不知道如何在密码中执行此操作的节点,但它显然没有在 gremlin 中列出代码。

于 2012-12-14T10:45:37.223 回答