2017-05-22 2 views
0

コメントなどが、私はWebサービスへのコメントJSONを送信する、(Facebookのような)に言及するとき、私は、社会的なネットワークを構築:neoism golangを使用したコレクションに関するCYPHERのクエリが難しいですか?

{ 
    "owner": 5,    // id of user write comment 
    "message": "text", 
    "mentions":[ 
    { 
     "id": 1,    // user id 
     "name": "mention",  // name is shown 
     "offset": 0,   // position of start of mention text 
     "length": 10   // length of mention text 
    }, 
    { 
     "id": 2,    // user id 
     "name": "mention",  // name is shown 
     "offset": 0,   // position of start of mention text 
     "length": 10   // length of mention text 
    } 
    ], 
} 

データモデル: (ユーザー) - [WRITE] - >(コメント{メッセージ}) - [言及{名前、オフセット、長さ}] - >(ユーザー)

ソースコードでは、私はコメント

cq := neoism.CypherQuery{ 
     Statement: stmt, 
     Parameters: params, 
     Result:  &res, 
    } 

のIDとRESを返すためのコードの下に使用私の問題は、Iドン」でありますこのためのクエリを書く方法を知っている。私にとってはあまりにも難しい。

答えて

1

ここでは、まずjsonを分解しないでCypherを実行する方法を説明します。

WITH {json} AS map 
MATCH (u:User) 
WHERE id(u)=map.owner 
CREATE (u)-[:WRITE]->(c:Comment{message:map.message}) 
FOREACH (mention IN map.mentions | 
    MATCH (u2:User) WHERE id(u2) = mention.id 
    CREATE (c)-[:MENTION{name:mention.name, length:mention.length, offset:mention.offset}]->(u2)) 
RETURN id(c) AS id 
+0

私はこのコードを遅く、ありがとうございます! –

関連する問題