当前位置: 首页 > 知识库问答 >
问题:

Neo4j图形数据库中复杂匹配评分时的性能?

牛景同
2023-03-14

我有Neo4J3.3.5图形数据库:27GB,50KK节点,500KK关系。索引打开。模式。个人电脑:16GB内存,4个核心。

MATCH (c:Company)-[r:HAS_BRANCH]->(b:Branch)
WHERE b.branchId in [27444, 1692, 23409, ...] //around 10 ids per query
RETURN 
c.companyId as Id, 
case r.branchType 
 when 0 then 25
 ... // //around 7 conditions per query 
 when 10 then 20 
end as Score

由于缺少后联合处理,我使用collect+unwind来合并所有关系的分数。

不幸的是,性能较低。我在5-10秒内得到一个关系(如上)查询的响应。当我试图将结果与collect+unwind组合时,查询“never”结束。

做这件事的更好/正确的方法是什么?也许我在图形设计上做错了什么?硬件配置到低?或者也许有一些算法可以与图库中的分数图(查询数据)匹配?

例如。用户可以搜索从西班牙生产木桌的新公司。

组合查询示例:

MATCH (c:Company)-[r:HAS_BRANCH]->(b:Branch)
WHERE b.branchId in ["27444" , "1692" , "23409" , "8744" , "9192" , "26591" , "21396" , "27151" , "20228" , "3517" , "25058" , "29549"] 
WITH case r.branchType 
when "0" then collect({id:c.companyId, score: 25}) 
 when "1" then collect({id:c.companyId, score: 19}) 
 when "2" then collect({id:c.companyId, score: 20}) 
 when "3" then collect({id:c.companyId, score: 19}) 
 when "4" then collect({id:c.companyId, score: 20}) 
 when "5" then collect({id:c.companyId, score: 15}) 
 when "6" then collect({id:c.companyId, score: 6}) 
 when "7" then collect({id:c.companyId, score: 5}) 
 when "8" then collect({id:c.companyId, score: 4}) 
 when "9" then collect({id:c.companyId, score: 4}) 
 when "10" then collect({id:c.companyId, score: 20}) 
end as rows
MATCH (c:Company)-[r:HAS_REVERTED_BRANCH]->(b:Branch)
WHERE b.branchId in ["27444" , "1692" , "23409" , "8744" , "9192" , "26591" , "21396" , "27151" , "20228" , "3517" , "25058" , "29549"] 
WITH rows + case r.branchType 
when "0" then collect({id:c.companyId, score: 25}) 
 when "1" then collect({id:c.companyId, score: 19}) 
 when "2" then collect({id:c.companyId, score: 20}) 
 when "3" then collect({id:c.companyId, score: 19}) 
 when "10" then collect({id:c.companyId, score: 20}) 
end as rows
MATCH (c:Company)-[r:HAS_COUNTRY]->(cou:Country)
WHERE cou.countryId in ["9580" , "18551" , "15895"] 
WITH rows + case r.branchType 
when "0" then collect({id:c.companyId, score: 30}) 
 when "2" then collect({id:c.companyId, score: 15}) 
 end as rows
... //here I would add in future other relations scoring
UNWIND rows AS row
RETURN row.id AS Id, sum(row.score) AS Score
ORDER BY Score DESC
LIMIT 100

共有1个答案

万嘉石
2023-03-14

您可以尝试这个查询,看看它是否更好:

MATCH (c:Company) WITH c
OPTIONAL MATCH (c)-[r1:HAS_BRANCH]->(b:Branch) WHERE b.branchId in ["27444" , "1692" , "23409" , "8744" , "9192" , "26591" , "21396" , "27151" , "20228" , "3517" , "25058" , "29549"] 
OPTIONAL MATCH (c)-[r2:HAS_REVERTED_BRANCH]->(c:Branch) WHERE c.branchId in ["27444" , "1692" , "23409" , "8744" , "9192" , "26591" , "21396" , "27151" , "20228" , "3517" , "25058" , "29549"] 
OPTIONAL MATCH (c)-[r3:HAS_COUNTRY]->(cou:Country) WHERE cou.countryId in ["9580" , "18551" , "15895"] 
WITH c, 
    case r1.branchType 
      when "0" then 25
      when "1" then 19 
      when "2" then 20 
      when "3" then 19 
      when "4" then 20 
      when "5" then 15 
      when "6" then 6 
      when "7" then 5 
      when "8" then 4 
      when "9" then 4 
      when "10" then 20 
    end as branchScore,
    case r2.branchType 
      when "0" then  25 
      when "1" then  19 
      when "2" then  20 
      when "3" then  19 
      when "10" then  20 
    end as revertedBranchScore,
    case r3.branchType 
      when "0" then  30
      when "2" then  15 
    end as countryScore

WITH c.id AS Id, branchScore + revertedBranchScore + countryScore AS Score
RETURN Id, sum(Score) AS Score
ORDER BY Score DESC
LIMIT 100

或者更好的方法是这个(但前提是公司节点必须链接到国家分支):

MATCH 
  (c:Company)-[r1:HAS_BRANCH]->(b:Branch),
  (c)-[r2:HAS_REVERTED_BRANCH]->(c:Branch),
  (c)-[r3:HAS_COUNTRY]->(cou:Country)
WHERE 
  b.branchId in ["27444" , "1692" , "23409" , "8744" , "9192" , "26591" , "21396" , "27151" , "20228" , "3517" , "25058" , "29549"] AND 
  c.branchId in ["27444" , "1692" , "23409" , "8744" , "9192" , "26591" , "21396" , "27151" , "20228" , "3517" , "25058" , "29549"] AND
  cou.countryId in ["9580" , "18551" , "15895"]
WITH c, 
    case r1.branchType 
      when "0" then 25
      when "1" then 19 
      when "2" then 20 
      when "3" then 19 
      when "4" then 20 
      when "5" then 15 
      when "6" then 6 
      when "7" then 5 
      when "8" then 4 
      when "9" then 4 
      when "10" then 20 
    end as branchScore,
    case r2.branchType 
      when "0" then  25 
      when "1" then  19 
      when "2" then  20 
      when "3" then  19 
      when "10" then  20 
    end as revertedBranchScore,
    case r3.branchType 
      when "0" then  30
      when "2" then  15 
    end as countryScore

WITH c.id AS Id, branchScore + revertedBranchScore + countryScore AS Score
RETURN Id, sum(Score) AS Score
ORDER BY Score DESC
LIMIT 100
 类似资料:
  • 问题内容: 问候, 除了Neo4J之外 , 是否有任何可用的开源图形数据库? 注意: 为什么不选择Neo4J? Neo4J是开源的,但是可以计算基元(节点数,关系和属性)。如果您将其用于商业用途。并且在官方网站上没有任何直接的定价信息。因此可能存在潜在的供应商锁定(尽管我刚成立我的公司,而且没有预算在软件上花钱。)所以这是不可行的。 问候, 问题答案: 如RobV所说,如果您的图形几乎可以以任何自

  • 5.1.2 图形是复杂数据 图形编程就是编写能创建和处理图形的程序。从一般的意义上说,图形也是数据,只不过与数值、字符串、列表等类型的数据相比,图形数据是非常复杂的数据。 首先,一个图形包含的信息是复杂的。例如,一个圆形需要用一个圆心和一个半径来定义。半径可以用一个简单的数值来表示,但圆心(平面上的一个点)却需要用两个数值型坐 标组成的元组来表示。这还只是大家在平面几何里认识的圆形,在实际的图形应

  • 我在Neo4j图形数据库上使用GRANDstack创建一个应用程序,我正在努力编写一个查询,该查询解压缩一个属性数组,匹配一些ID,拉回与ID相关的名称,并将它们重新打包到一个新的数组中。 本质上,我有内存节点(Mems)和Person节点(Person),它们的关系如下:(Mems)-[WITH]->(Person)。也就是说,你可以对你和多个人在一起的事情有一个记忆。Mems节点包含perso

  • 本文向大家介绍数据结构中的时空复杂性,包括了数据结构中的时空复杂性的使用技巧和注意事项,需要的朋友参考一下 算法分析 可以在实施之前和实施之后的两个不同阶段进行算法效率分析,如下 先验分析-这被定义为算法的理论分析。通过假设所有其他因素(例如处理器速度)是恒定的,并且对实现没有影响,来衡量算法的效率。 后验分析-定义为算法的经验分析。所选算法是使用编程语言实现的。接下来,所选算法在目标计算机上执行

  • 复杂的画图函数利用2-D线性转换能让你画出任意图形。这个功能与Adobe? PostScript 语言实现的功能很相似,在X和Win32上,在画线段之前所有的转换顶点都是用整数表示,这就限制了画图的精确性。如果要画比较精确的图形,最好用OpenGL来画。 void fl_push_matrix() void fl_pop_matrix() 保存和恢复当前的转换,堆栈的最大深度为4 void fl

  • 有没有用Cypher编写递归查询的方法?我必须遍历从一组节点(带有标签)到另一组节点的所有路径。该图是定向的,并且有多个路径,如 递归查询必须概述此伪代码 这个问题的解决方案不一定是递归的。任何其他解决方案都将受到赞赏。 编辑:在查询开始之前,根据需要将设置为一些值。并且图中的所有其他节点(例如)都有它们的。 有多个定向路径,如。对于这些路径中的每个节点(m,n,o,..)-[*]->y-->x-