Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查询使Twitter流应用程序在保存数据时速度过慢_Twitter_Neo4j_Cypher_Twitter4j - Fatal编程技术网

查询使Twitter流应用程序在保存数据时速度过慢

查询使Twitter流应用程序在保存数据时速度过慢,twitter,neo4j,cypher,twitter4j,Twitter,Neo4j,Cypher,Twitter4j,我有一个应用程序,它将存储在Neo4j数据库中的Twitter数据流化。我存储的数据涉及tweet、用户、hashtag及其关系(用户发布tweet、tweet标签hashtags、用户转发tweet)。 现在,每当我收到一条新推特,我所做的就是: 检查数据库是否已经包含tweet:如果是,我用新信息(retweet count,比如count)更新它,否则我保存它 检查数据库是否已经包含该用户:如果是,我用新信息更新它,否则保存它 检查数据库是否已经包含hashtag:如果没有,我添加它

我有一个应用程序,它将存储在Neo4j数据库中的Twitter数据流化。我存储的数据涉及tweet、用户、hashtag及其关系(用户发布tweet、tweet标签hashtags、用户转发tweet)。 现在,每当我收到一条新推特,我所做的就是:

  • 检查数据库是否已经包含tweet:如果是,我用新信息(retweet count,比如count)更新它,否则我保存它
  • 检查数据库是否已经包含该用户:如果是,我用新信息更新它,否则保存它
  • 检查数据库是否已经包含hashtag:如果没有,我添加它
依此类推,保存关系的过程也是一样的

以下是查询:

static String cqlAddTweet = "merge (n:Tweet{tweet_id: {2}}) on create set n.text={1}, n.location={3}, n.likecount={4}, n.retweetcount={5}, n.topic={6}, n.created_at={7} on match set n.likecount={4}, n.retweetcount={5}";
static String cqlAddHT = "merge (n:Hashtag{text:{1}})";
static String cqlHTToTweet = "match (n:Tweet),(m:Hashtag) where n.tweet_id={1} and m.text={2} merge (n)-[:TAGS]->(m)";
static String cqlAddUser = "merge (n:User{user_id:{3}}) on create set n.name={1}, n.username={2}, n.followers={4}, n.following={5}, n.profilePic={6} on match set n.name={1}, n.username={2}, n.followers={4}, n.following={5}, n.profilePic={6}";
static String cqlUserToTweet = "match (n:User),(m:Tweet) where m.tweet_id={2} and n.user_id={1} merge (n)-[:POSTS]->(m)";
static String cqlUserRetweets = "match (n:Tweet{tweet_id:{1}}), (u:User{user_id:{2}}) create (u)-[:RETWEETS]->(n)";
由于它在保存数据方面非常慢,我认为如果我不运行每次扫描数据的所有查询,这个系统可以有更好的性能

你对改进我的申请有什么建议吗

谢谢您,如果这看起来有点傻,请提前原谅。

请确保您在以下标签/属性对上有(或,如果合适)。这将允许您的查询避免扫描具有相同标签的所有节点(在启动查询时)

  • :Tweet(Tweet\u id)
  • :标签(文本)
  • :用户(用户id)
顺便说一下,可以简化几个查询(但这不应影响性能):


谢谢你的建议。不幸的是,添加索引或约束并没有提高性能。
static String cqlAddTweet = "MERGE (n:Tweet{tweet_id: {2}}) ON CREATE SET n.text={1}, n.location={3}, n.topic={6}, n.created_at={7} SET n.likecount={4}, n.retweetcount={5}";
static String cqlAddUser = "MERGE (n:User{user_id:{3}}) SET n.name={1}, n.username={2}, n.followers={4}, n.following={5}, n.profilePic={6}";