与Cypher& amp;创建唯一 [英] Struggling with Cypher & CREATE UNIQUE

查看:166
本文介绍了与Cypher& amp;创建唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读来自文本文件的足球比赛数据,并希望创建比赛和裁判节点。我希望逻辑工作的方式是创建一个匹配节点,然后获取裁判名称并仅在裁判不存在的情况下创建裁判节点,否则我只将现有裁判与该匹配相关联。我目前没有根节点,我不确定是否应该创建一个(对图形建模来说很新颖)。



我有以下查询,我认为我很接近但没有。

  $ match = $ client-> makeNode(); 
$ match-> setProperty('label',match:。$ feed ['match_number'])
- > setProperty('type',match) - > save( );

//现在创建匹配节点让我们看看feed中当前的裁判是否已经存在 p>

  $ queryString =START match = node({nodeId})。 < -----需要查看所有案例????? 
CREATE UNIQUE(referee {label:{name},type:'referee'}) - [:REFEREED {label:'REFEREED'}] - >(match)。

$ query = new Neo4j\Cypher\Query($ client,$ queryString,array('nodeId'=> $ match-> getId(),'name'=> $饲料[ 'referee_name']));
$ result = $ query-> getResultSet();

有人可以协助吗?

解决方案

目前看起来可以满足您发布的查询的可能模型之一:

 (Team) -  [:PLAYS]  - >(Match)

(Match) - [:HAS_REFEREE] - > ;(裁判)

(匹配) - [:PLAYED_IN] - >(城市)

PLAYS关系可以有一个属性来表明球队是否是主队。您也可以在PLAYS关系上拥有一个属性来表明该团队是否获胜。或者,如果胜利是你所寻找的重要部分,你可以创建一个额外的关系,如(Team) - [:WON] - >(Match) (尽管如此,你需要考虑如何模拟抽签。对于一场比赛,任何一支队伍都没有WON关系可能表示抽签)。


  1. 特定裁判的所有比赛:从裁判开始,穿过Match to the Cities。您可以为裁判员指出一些独特的属性,以便能够快速查找他们。


  2. 裁判员工作和主队获胜的所有比赛:从裁判,找到他所有的比赛,过滤WON关系/财产和主队财产。


  3. 所有主队胜率最高的裁判:与上面相同,从所有裁判开始

  4. / li>

您可能会移动一些东西,具体取决于您想要回答的更多问题(特别是主队属性,WIN / LOSE关系或属性等等)

我认为你根本不需要根节点。你可以索引所有比赛/城市/裁判等等,如果你想找到他们所有的人。/ b

I am reading soccer match data from text file and want to create matches and referee nodes. The way I want logic to work is that I create a match node and then I get the referee name and create the referee node ONLY if that referee does not already exist else I just link the existing referee to the match. I presently DO NOT have a root node and am not sure if I should create one (very new to graph modeling).

I have the following query in which I think I am close but not there.

$match= $client->makeNode();
$match->setProperty('label', "match: ".$feed['match_number'])
      ->setProperty('type', "match")->save();

//now that the match node is created lets see if the current referee in feed exists already

$queryString = "START match=node({nodeId}) ".   <----- NEED TO LOOK AT ALL CASES?????
"CREATE UNIQUE (referee{label:{name}, type:'referee'})-[:REFEREED{ label:'REFEREED' }]->(match)"."RETURN referee";

$query = new Neo4j\Cypher\Query($client, $queryString, array('nodeId' => $match->getId(),'name' => $feed['referee_name']));
$result = $query->getResultSet();

Can someone please assist?

解决方案

One of the possible models that at the moment seem to satisfy the queries you've posted:

(Team)-[:PLAYS]->(Match)

(Match)-[:HAS_REFEREE]->(Referee)

(Match)-[:PLAYED_IN]->(City)

The PLAYS relation could have a property to indicate if the team was the home team. You could also have a property on the PLAYS relation to indicate whether that team won or not. Or if winning is a big part of what you're looking for, you can create an extra relation such as (Team)-[:WON]->(Match) (though then you need to think about how to model draws. The absence of a WON relation on either of the two teams for a match could indicate a draw maybe).

  1. All matches for a particular referee: Start at the referee, traverse through the Match to the Cities. You might index some unique property of the referee to be able to look him up quickly

  2. All matches where the referee worked and the home team won: Start at the referee, find all his matches, filter on the WON relation/property and the home team property

  3. All referees that have the highest count of wins for the home team: Same as above, start at all referees

  4. Most active referees for a city: Start at the city, find all matches and their referees

You might move things around a bit depending on more questions that you want to answer (especially home team properties, WIN/LOSE relations or properties etc.)

And I don't think you need the root node at all. You can index all matches/cities/referees etc if you want to find all of them

这篇关于与Cypher&amp; amp;创建唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆