我有一个带有rails的嵌入式neo4j服务器。
这些配置如下:
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在15lakh电影节点周围。下面的查询是围绕5secs执行的。
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随用户滚动结果而变化。
而另一个旨在从特定导演那里获得电影的查询则围绕着9secs进行。
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 如何减少查询执行时间?
发布于 2014-07-07 12:15:22
关于第一个问题:
您可以通过使用:NEXT_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 (d:Director) set d.lowerName = LOWER(d.name)确保在标签Director和属性LowerName上有索引
CREATE INDEX ON :Director(lowerName)您的查询应该如下所示:
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 https://stackoverflow.com/questions/24607605
复制相似问题