1

我有一个相当简单的图表。它只有大约 100 个节点和 400 个关系。我正在尝试运行各种密码查询,这些查询根据某些关系的存在对结果进行排名。但是,即使使用小型数据库,这些查询也会超时。谁能确定我的查询存在导致超时的问题?

下面的查询搜索各种模式。如果模式存在,它将对关系应用权重。最后,它结合权重并对结果进行排序,因此具有最高权重(最重要的关系)的节点被优先考虑。

START node=node(1) 
MATCH  (node)-[a?:REQUIRES]-(thing0)-[?:RELATED]-(stuff) 
,(node)-[b?:REQUIRES]-(thing1)-[:RELATED]-(system1)-[:COMPOSITION]-(something1)-[?:VERSION]-(stuff) 
,(node)-[c?:REQUIRES]-(thing2)-[:RELATED]-(something2)-[?:VERSION]-(stuff) 
,(node)-[d?:REQUIRES]-(thing3)-[:REQUIRES]-(project1)-[:REQUIRES]-(thing6)-[?:RELATED]-(stuff) 
,(node)-[e?:REQUIRES]-(thing4)-[:DESCRIBES]-(part)-[:DESCRIBES]-(thing5)-[?:RELATED]-(stuff) 
WITH stuff
, count(distinct a)*.15 as shareA
, count(distinct b)*.35 as shareB
, count(distinct c)*.25 as shareC
, count(distinct d)*.10 as shareD
, count(distinct e)*.15 as shareE 
WHERE has(stuff.__type__) 
AND stuff.__type__='full.namespace.to.stuff' 
SET stuff.weight = shareA + shareB + shareC + shareD + shareE 
RETURN DISTINCT stuff 
ORDER BY stuff.weight DESC 
4

1 回答 1

1

我认为你会想要去掉选项,并在一个 BATCH 请求或事务中的一些密码语句中执行此操作。

START stuff=node(*) 
WHERE has(stuff.__type__) AND stuff.__type__='full.namespace.to.stuff' 
SET stuff.weight = 0.0;

START node=node(1) 
MATCH  (node)-[a:REQUIRES]-(thing)-[:RELATED]-(stuff) 
WHERE has(stuff.__type__) AND stuff.__type__='full.namespace.to.stuff' 
SET stuff.weight = stuff.weight + COUNT(DISTINCT a)*.15;

START node=node(1) 
MATCH (node)-[b:REQUIRES]-(thing)-[:RELATED]-(system1)-[:COMPOSITION]-(something1)-[:VERSION]-(stuff) 
WHERE has(stuff.__type__) AND stuff.__type__='full.namespace.to.stuff' 
SET stuff.weight = stuff.weight + COUNT(DISTINCT b)*.35

START node=node(1) 
MATCH (node)-[c:REQUIRES]-(thing2)-[:RELATED]-(something2)-[:VERSION]-(stuff) 
WHERE has(stuff.__type__) AND stuff.__type__='full.namespace.to.stuff' 
SET stuff.weight = stuff.weight + COUNT(DISTINCT c)*.25

START node=node(1) 
MATCH (node)-[d:REQUIRES]-(thing3)-[:REQUIRES]-(project1)-[:REQUIRES]-(thing6)-[:RELATED]-(stuff) 
WHERE has(stuff.__type__) AND stuff.__type__='full.namespace.to.stuff' 
SET stuff.weight = stuff.weight + COUNT(DISTINCT d)*.10

START node=node(1) 
MATCH (node)-[e:REQUIRES]-(thing4)-[:DESCRIBES]-(part)-[:DESCRIBES]-(thing5)-[:RELATED]-(stuff) 
WHERE has(stuff.__type__) AND stuff.__type__='full.namespace.to.stuff' 
SET stuff.weight = stuff.weight + COUNT(DISTINCT e)*.15

START stuff=node(*) 
WHERE has(stuff.__type__) AND stuff.__type__='full.namespace.to.stuff' 
RETURN DISTINCT stuff 
ORDER BY stuff.weight DESC 

你可以用“WITH”链接它,但我认为这让它很混乱。

于 2013-06-18T04:11:44.727 回答