![]() ![]() Here we take a slightly different approach where we make use ofįunctions that we can apply to a matching path. WITH day.name as dayName, COLLECT() AS opponentsĮXTRACT(y in FILTER(x in opponents: TYPE(HEAD(TAIL(x))) = "home_team") : HEAD(y)) AS home,ĮXTRACT(y in FILTER(x in opponents : TYPE(HEAD(TAIL(x))) = "away_team") : HEAD(y)) AS awayĮXTRACT(team in home: team.name) AS homeOpponents,ĮXTRACT(team in away: team.name) AS awayOpponents REDUCE(totalGames=0, game in games : totalGames + 1) as total +-+Īn alternative way of writing the initial query would be the following which Michael Hunger suggested on the thread: START team = node:teams('name:"Manchester United"') REDUCE(awayGames=0, game in EXTRACT(c in FILTER(x in games: head(x) = "away_team") : HEAD(TAIL(c))) : awayGames + 1) as away, REDUCE(homeGames=0, game in EXTRACT(c in FILTER(x in games: head(x) = "home_team") : HEAD(TAIL(c))) : homeGames + 1) as home, The REDUCE function to do this: START team = node:teams('name:"Manchester United"') It’s probably more useful to summarise how many games were played onĮach day at home and away rather than who they’re against and we can use Adding televised matches is perhaps another layer to add to the graph. Televised so I thought they’d be more evenly split between home and away Play away on a Sunday – I think all of those games were probably I thought it was quite interesting how many games Manchester United In actual fact the away teams would be in a (I ran the query twice alternating between the last two lines so We then use the FILTER function to choose either the opponents Manchester United played at home or away and then we use the EXTRACT function to get the opponent from the tuple: +-+ If we run the query just up to the last WITH we get the following result: +-+ Relationship since we’ve already matched our team. The only other node that can match the ‘home_team|away_team” Teams per game we’re able to get the opponent node easily because it’s We use a similar approach with COLLECT as in the previous post whereby we have a collection of tuples describing whether Manchester United were at home or not and who they were playing.Ī neat thing that Wes pointed out is that since there are only 2 WITH d, COLLECT() AS gamesĮXTRACT(c in FILTER(x in games: HEAD(x) = "home_team") : HEAD(TAIL(c))) AS home,ĮXTRACT(c in FILTER(x in games: HEAD(x) = "away_team") : HEAD(TAIL(c))) AS away With a lot of help from Wes Freeman we ended up with the following query which does the job: START team = node:teams('name:"Manchester United"') I thought it’d be cool if we could separate the games on each dayīased on whether Manchester United were playing at home or away. ‘Manchester United’ and the word ‘vs’ to get the opponent’s name. Two teams is in the ‘name’ property of a game node and we’ve removed The way we’ve got the opponents is a bit of a hack – the name of the RETURN DISTINCT day.name, COLLECT(TRIM(REPLACE(REPLACE(game.name, "Manchester United", ""), "vs", ""))) +-+ START team = node:teams('name:"Manchester United"') I started out with a query which grouped the data set by day and showed the opponents that were played on that day: Using a similar structure, you should be able to adapt this for your own use to solve your own problems.As I mentioned in my last post I’m trying to get the hang of the WITH statement in neo4j’s cypher query language and I found another application when trying to work out which opponents teams played on certain days. The code in the penultimate section (the long code snippet) shows you how to do this. Therefore you will need to take your fate into your own hands and extract the data yourself. Hopefully, they are enough! ConclusionĪs I eventually found out and have now mentioned to you, at the time of writing this post, Spring Data Neo4j does not support the automatic mapping of queries containing paths. I don’t think there is any need to explain the rest of the example, I tidied up the code as best I could and added comments for clarity. You do not need to extend this class, but I suggest you do. This iteration of PathRepository extends SimpleNeo4jRepository to inherit some of the more common queries without requiring you to implement them yourself. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |