【问题标题】:Have difficult CYPHER query about collection using neoism golang?对使用 Neoism golang 的收集有困难的 CYPHER 查询吗?
【发布时间】:2017-10-22 09:32:55
【问题描述】:

我建立了一个社交网络,当评论包括提及(如 Facebook)时,我将评论 json 发送到 web 服务:

{
  "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
    }
  ],
}

数据模型: (User)-[WRITE]->(Comment{message})-[MENTION{name,offset,length}]->(User)

在源代码中,我使用下面的代码返回带有注释 ID 的 res

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

我的问题是我不知道如何为此编写查询。对我来说太难了。

【问题讨论】:

    标签: neo4j cypher mention neoism


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多