关于多跳的特殊逻辑nGQL咨询

Hi, 目前遇到一个场景,结构很简单,是这样,

节点A → 节点B → 节点C

定义连接的边为:边edgeAB, 边edgeBC

edgeAB中有properties:scoreAB

edgeBC中有一个properties:scoreBC

定义两个常数n, m

想从某个A节点开始,获取到连接的Top n个B节点(根据scroeAB排序), 再从这n个B节点,每个B节点获取Top m个C节点(根据scoreBC排序),得到n*m个C节点,并去重后返回。

这种逻辑有办法实现吗? 目前看了官方文档好像没有什么好的办法

有人解答这个问题吗

MATCH (v:player)-[e1:follow]->(v2) WHERE id(v)==‘player100’ with distinct e1.degree as degree, v2 order by degree DESC limit 10 match (v2)-[e2:serve]->(v3) return distinct e2.end_year as year, v3 order by year DESC limit 10;

相关文档参考:

查询语句还是很强大的,可以多研究下

match (A)-[e1:edgeAB]->(B) WITH B, e1.scoreAB AS scoreAB ORDER BY scoreAB LIMIT n match (B)-[e2:edgeBC]->(C) return C order by e2.scoreBC LIMIT n * m

可以做到n*m个C,
但是不能保证每个B最多m个C

哦,对,我写的漏了n*m这个了

感谢各位大佬回答,看了下应该是目前没办法限制二跳的时候每个节点搜索边的数量是吗,也就是没办法限制这个场景里的m

是的

好的谢谢

我们这边想了下,是不是可以这样,在edgeBC 里 加一个properties: rank, 比如 { “rank” : 1, “scroeBC” : 0.111}, 然后二跳的时候 where rank < m, 这样是不是就可以限制 m 了

like this:

match (A)-[e1:edgeAB]->(B) WITH B, e1.scoreAB AS scoreAB ORDER BY scoreAB LIMIT n match (B)-[e2:edgeBC]->(C) where e2.rank < m return C order by e2.scoreBC

有大佬看看下这样可行吗 :smile:

可以,不过你得保证rank满足你的约束

此话题已在最后回复的 30 天后被自动关闭。不再允许新回复。