优化Neo4j Cypher查询匹配属性

时间:2013-03-12 09:17:07

标签: neo4j cypher

我的Cypher查询表现极差(约30秒):

START foo=node:foos('Name:*')
MATCH foo<-[:HasMember]-()<-[:PartOf]-()<-[:Connected]-bar
WHERE foo.Name IN ["name1", "name2"] AND bar.Enabled = true
RETURN DISTINCT bar.Guid AS Guid, foo.Name AS Name

我认为发生的事情是Lucene索引用于提取所有值,然后使用图形搜索来匹配集合中的名称,因为如果我将查询更改为下面的查询,那么它就是订单更快(16毫秒):

START foo=node:foos('Name:"name1" OR Name:"name2"')
MATCH foo<-[:HasMember]-()<-[:PartOf]-()<-[:Connected]-bar
WHERE bar.Enabled = true
RETURN DISTINCT bar.Guid AS Guid, foo.Name AS Name

有没有办法让第一个查询以第二个查询的速度执行,而无需手动构建名称集中的Lucene查询?

另一种选择是使用遍历,但如果可能的话,我更愿意留在Cypher-land。

1 个答案:

答案 0 :(得分:3)

也许如果您不想构建查询,请尝试先前过滤? 像

START foo=node:foos('Name:*')
WHERE foo.Name IN ["name1", "name2"]
WITH foo
MATCH foo<-[:HasMember]-()<-[:PartOf]-()<-[:Connected]-bar
WHERE bar.Enabled = true
RETURN DISTINCT bar.Guid AS Guid, foo.Name AS Name