【发布时间】:2015-02-16 14:18:48
【问题描述】:
我有一段时间尝试在 py2neo 中创建很多笔记。这些节点基于推文直播,我想在其中绘制推文、关于谁发推文的信息以及推文与其他节点之间的关系(例如转发推文、用户提及和标签)。
我尝试的是进行大型密码查询,使用 MERGE 创建/获取用户和推文的 ID,并将它们链接起来。我的想法是有以下节点:
- 用户节点
- 推特
- 标签
- 位置(用于推文)
- 位置(供用户使用)
- 语言
- 性别
- 时区
以及我需要查找的链接:
- 提及
- 转发推文
这写了很多,我做这样的事情:
statement = "MERGE (tUser:TwitterUser {id:{tuID}}) " \
"ON CREATE SET " \
"tUser.displayName = {tdNAME}, " \
"tUser.summary = {tdSummary}, " \
"tUser.link = {tdLink}, " \
"tUser.preferredUsername = {tdPreferredUsername}, " \
"tUser.account_created = {tdAccount_created}, " \
"tUser.last_lookup = 'Newer' " \
"" \
"MERGE (user:Person {name:{userName}})-[:twitter_acct]->(tUser) " \
"" \
"MERGE (gender:Gender {gender: {GENDER}})" \
"MERGE (user)-[:has_gender]->(gender) " \
"" \
"MERGE (user)-[:tweeted]->(tweet:Tweet {id:{tID}}) " \
"ON CREATE SET " \
"tweet.type = {tType}, " \
"tweet.link = {tLink}, " \
"tweet.body = {tBody}, " \
"tweet.postedTime = {tPostedTime} " \
"" \
"MERGE (timezone:TimeZone {name:{timeZoneName}}) " \
"MERGE (user)-[:has_time]->(timezone)" \
"" \
"MERGE (user)-[:use]->(generator:Generator {name: {generator}}) " \
"ON CREATE SET " \
"generator.link = {generatorLink} " \
"" \
"MERGE (tweet)-[:tweeted_in]->(tLocation:Location {name: {tLocationName}}) " \
"MERGE (tLocation)-[:in]->(tCountry:Country {name: {tCountryName}}) " \
"" \
"MERGE (user)-[:lives_in]->(uLocation:Location {name: {uLocationName}}) " \
"" \
"RETURN user"
问题是:当我尝试在我的 Neo4J 数据库中插入推文时,它无法跟随,当我尝试仅使用我制作的一组数据时,它仍然做得很慢。我尝试过使用批处理,但仍然很慢。
解决办法是少做点,买一台更好的机器还是..?使用模式(如果我重新启动服务,我如何获得正确的用户节点 ID)。
【问题讨论】:
标签: python python-3.x neo4j cypher py2neo