加速neo4j密码查询
我有一个嵌入式neo4j服务器,带有ruby on rails 以下是配置:加速neo4j密码查询,neo4j,cypher,Neo4j,Cypher,我有一个嵌入式neo4j服务器,带有ruby on rails 以下是配置: neostore.nodestore.db.mapped_memory=25M neostore.relationshipstore.db.mapped_memory=240M neostore.propertystore.db.mapped_memory=230M neostore.propertystore.db.strings.mapped_memory=1200M neostore.propertystore.
neostore.nodestore.db.mapped_memory=25M
neostore.relationshipstore.db.mapped_memory=240M
neostore.propertystore.db.mapped_memory=230M
neostore.propertystore.db.strings.mapped_memory=1200M
neostore.propertystore.db.arrays.mapped_memory=130M
wrapper.java.initmemory=1024
wrapper.java.maxmemory=2048
大约有150万个电影节点。下面的查询大约需要5秒才能执行
MATCH (movie:Movie)
WITH movie, toInt(movie.reviews_count) + toInt(movie.ratings_count) AS weight
RETURN movie, weight as weight
ORDER BY weight DESC
SKIP skip_count
LIMIT 10
这里的skip_count
随着用户滚动查看结果而变化
这是另一个旨在从特定导演那里获取电影的查询,大约需要9秒
MATCH (movie:Movie) , (director:Director)-[:Directed]->(movie)
WHERE director.name =~ '(?i)DIRECTOR_NAME'
WITH movie, toInt(movie.ratings_count) * toInt(movie.reviews_count) * toInt(movie.rating) AS total_weight
RETURN movie, total_weight
ORDER BY total_weight DESC, movie.rating DESC
LIMIT 10
如何减少查询执行时间?关于第一次查询:
您可以通过使用:NEXT\u weight
关系(按权重降序排列)连接所有电影节点来明确图表中的权重顺序,以便电影建立一个链接列表
您的查询如下所示:
MATCH p=(:Movie {name:'<name of movie with highest weight>'})-[:NEXT_WEIGHT*..1000]-()
WHERE length(p)>skip_count AND length(p)<skip_count+limit
WITH p
ORDER BY length(p)
WITH last(nodes(p)) as movie
RETURN movie, toInt(movie.reviews_count) + toInt(movie.ratings_count) AS weight
MATCH (director:Director)-[:Directed]->(movie)
WHERE director.name = {directorName}
RETURN movie, toInt(movie.ratings_count) * toInt(movie.reviews_count) * toInt(movie.rating) AS total_weight
ORDER BY total_weight DESC, movie.rating DESC
LIMIT 10
确保在标签控制器
和属性下部名称
上有索引:
CREATE INDEX ON :Director(lowerName)
您的查询应该如下所示:
MATCH p=(:Movie {name:'<name of movie with highest weight>'})-[:NEXT_WEIGHT*..1000]-()
WHERE length(p)>skip_count AND length(p)<skip_count+limit
WITH p
ORDER BY length(p)
WITH last(nodes(p)) as movie
RETURN movie, toInt(movie.reviews_count) + toInt(movie.ratings_count) AS weight
MATCH (director:Director)-[:Directed]->(movie)
WHERE director.name = {directorName}
RETURN movie, toInt(movie.ratings_count) * toInt(movie.reviews_count) * toInt(movie.rating) AS total_weight
ORDER BY total_weight DESC, movie.rating DESC
LIMIT 10
嗨,斯蒂芬!谢谢你的回复。我认为第一个查询可以用这种方式构造,以提高效率。匹配p=(:Movie{name:'})-[:NEXT_WEIGHT*limit]()返回节点(p)(因为我可以跟踪用户会话中显示的最后一部电影)。对于第二个问题:是否有一种方法可以使用下一个权重
来避免使用order by
?我想一个导演只有一个答案是肯定的,这似乎对这种情况很有效。但是,是否有任何方法可以使用NEXT\u-WEIGHT
关系执行此操作。因此,它也可以用于其他类似的情况。您可以使用第一个语句,使用另一个WITH
和MATCH
检查电影是否与导演匹配。