我有一个相当简单的图表。它只有大约100个节点和400个关系。我正在尝试运行各种cypher查询,根据某些关系的存在对结果进行排名。但是,即使使用小型数据库,这些查询也会超时。任何人都可以识别出导致超时的查询问题吗?
下面的查询会搜索各种模式。如果模式存在,则会对关系应用权重。最后,它结合权重并对结果进行排名,以便优先考虑权重最高的节点(最重要的关系)。
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
答案 0 :(得分: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"但我觉得这很麻烦。