本文介绍了查找每个节点的顶​​级排序模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据以这种方式建模:

My data is modeled this way:

我有足球运动员,进球和比赛的节点.玩家通过[:played]关系进行比赛,并通过[:scored]关系进行进球.目标已连接以与[:scoredIn]关系匹配.每个匹配项都有一个(长)日期属性.

I have nodes of soccer players, goals and matches. player is connected to match with [:played] relation, and to goal with [:scored] relation. goal is connected to match with [:scoredIn] relation. each match has a (Long) date property.

我正在尝试寻找在最近5场比赛中得分最高的球员(在match.date属性上按DESC排序).

I'm trying to find players who scored the most goals in their last 5 matches (with DESC sorting on the match.date property).

最有效的方法是什么?我可以遍历每个球员的比赛排序后的DESC,保留比赛ID,然后在这些相关比赛中找到(player)-[:scored]->(goal)-[:scoredIn]->(m)模式,但这是非常慢.

What would be the most efficient way? I can go over every player's matches sorted DESC, keep the matches ids and then find the (player)-[:scored]->(goal)-[:scoredIn]->(m) pattern into these relevant matches, but this is very slow.

好像我缺少什么,如何通过相对排序找到这些模式?

Seems like I'm missing something, how can I find these patterns with the relative sorting?

谢谢

推荐答案

它可能有助于剖析或解释您的查询,并将生成的计划粘贴到您的描述中(所有元素都展开).

It may help to PROFILE or EXPLAIN your query and paste the resulting plan into your description (with all elements expanded).

对它进行刺耳,似乎我们正在寻找最适合遍历的查询.单个玩家可能已经打进许多目标,并且不得不扩展每个目标并对游戏中所得分入的目标进行散列连接,听起来可能会非常昂贵.

Taking a stab at it, it sounds like we're looking for the most traversal-friendly query. A single player may have scored many many goals, and having to expand each goal and do a hash join to the goals scored in a game sounds like it can be very expensive.

如果相反,我们获得了玩家的最近5场比赛,然后获得了游戏中得分的目标并根据玩家过滤了目标,那么效率可能更高.

If instead we get a player's last 5 games, and then get the goals scored in the game and filter those based on the player, that may be more efficient.

类似的东西:

MATCH (p:Player)-[:played]->(m)
WITH p, m
ORDER BY m.date DESC
WITH p, COLLECT(m)[..5] as matches
UNWIND matches as match
MATCH (match)<-[:scoredin]-(g)
WHERE (g)<-[:scored]-(p)
RETURN p, COUNT(g) as goalsInLast5
ORDER BY goalsInLast5 DESC
LIMIT 10 // or whichever top n you want

对于大图,这可能仍然是一个昂贵的查询.

With a large graph, this may still be an expensive query.

作为一个小改进,您可能需要考虑将每位球员每场比赛的进球数分组,而不是为每个进球数选择一个进球节点.

As a small improvement, you may want to consider grouping goals per match per player instead of a single goal node for each goal.

类似的东西:

这篇关于查找每个节点的顶​​级排序模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 07:59