方法:找出标签为PEOPLE1或者标签为CORPID1的节点
MATCH (a:PEOPLE1) ,(b:CORPID1)
with [a,b] as m
unwind m as mm
RETURN mm;
有没有更高效的写法,以上写法 一旦数据量大了。效率就很低
两位老师。我这里主要是做算法用的。
官网标签传播算法是algo.labelPropagation 有三个参数 1:要扫描的节点Id 2.cypher语句 3.方向 4.参数
CALL algo.labelPropagation( ‘MATCH (p:User) RETURN id§ as id, p.weight as weight, id§ as value’, ‘MATCH (p1:User)-[f:FRIEND]->(p2:User)RETURN id(p1) as source, id(p2) as target, f.weight as weight’, “OUT”, {graph:‘cypher’,write:true});
官网给的例子只能用一个标签去匹配节点,实际运用中寻找团伙一般都不止一个标签。这里用union可以返回多个标签的id。避免全库扫描 直接写成
'MATCH (a) RETURN id(a) as id, id(a) as value 也可以。但是会进行全库扫。
CALL algo.labelPropagation( ‘MATCH (a:PEOPLE1) RETURN id(a) as id, id(a) as value union all match (a:CORPID1) RETURN id(a) as id, id(a) as value’, ‘match (a:PEOPLE1)-[fr]->(b:CORPID1)-[:dk]->(c:LOANID1)<-[:db]-(a)-[:dk]->(d:LOANID1)<-[:db]-(b) RETURN id(a) as source, id(b) as target’, “OUT”, {graph:‘cypher’,write:true,partitionProperty:‘partitionx’}); match(n:PEOPLE1),(m:CORPID1) return n,m;
@bingo 我需要将标签作为参数传入进来,然后进行查询,类似于这种 name = "六味地黄胶囊" data = graph.run(‘match (n {name:$name}) return n limit 5’, name=name)
只不过我需要把变量换成label,如果我这么写肯定报错 name = "六味地黄胶囊" data = graph.run(‘match (n:$label) return n limit 5’, label=name)
不知道您有没有什么办法解决这个问题,谢谢