gpt4 book ai didi

php - 有什么最好的方法可以在 MySQL 中存储推文吗?

转载 作者:可可西里 更新时间:2023-11-01 08:20:49 26 4
gpt4 key购买 nike

从这里(https://dev.twitter.com/docs/api/1/get/statuses/home_timeline)可以看出,一条推文有很多信息(字段),因此在 MySQL 中存储推文信息并不容易。

如果我把这个 JSON 做成数组,它就不会是 1 深度数组。例如,就像这个 JSON 中的 URL 实体一样,它可能在一个“实体”字段中有很多 URL。

我是否应该将此信息存储为一个字符串,如“urls[{"aa": a, "bb": b}, {"aa": c, "bb": d}]"在一个字段中?或者有什么最好的存储方式吗?

{
"coordinates": null,
"favorited": false,
"created_at": "Fri Jul 16 16:58:46 +0000 2010",
"truncated": false,
"entities": {
"urls": [
{
"expanded_url": null,
"url": "http://www.flickr.com/photos/cindyli/4799054041/",
"indices": [
75,
123
]
}
],
"hashtags": [

],
"user_mentions": [
{
"name": "Stephanie",
"id": 15473839,
"indices": [
27,
39
],
"screen_name": "craftybeans"
}
]
},
"text": "got a lovely surprise from @craftybeans. She sent me the best tshirt ever. http://www.flickr.com/photos/cindyli/4799054041/ ::giggles::",
"annotations": null,
"contributors": null,
"id": 18700887835,
"geo": null,
"in_reply_to_user_id": null,
"place": null,
"in_reply_to_screen_name": null,
"user": {
"name": "cindy li",
"profile_sidebar_border_color": "AD0066",
"profile_background_tile": false,
"profile_sidebar_fill_color": "AD0066",
"created_at": "Wed Nov 29 06:08:08 +0000 2006",
"profile_image_url": "http://a1.twimg.com/profile_images/553508996/43082001_N00_normal.jpg",
"location": "San Francisco, CA",
"profile_link_color": "FF8500",
"follow_request_sent": false,
"url": "http://www.cindyli.com",
"favourites_count": 465,
"contributors_enabled": false,
"utc_offset": -28800,
"id": 29733,
"profile_use_background_image": true,
"profile_text_color": "000000",
"protected": false,
"followers_count": 3395,
"lang": "en",
"notifications": true,
"time_zone": "Pacific Time (US & Canada)",
"verified": false,
"profile_background_color": "cfe8f6",
"geo_enabled": true,
"description": "Just me, Cindy Li.Giving cute substance since 1997.\r\nMarried to @themattharris.\r\nProduct designer for Yahoo! ",
"friends_count": 542,
"statuses_count": 4847,
"profile_background_image_url": "http://a3.twimg.com/profile_background_images/3368753/twitter_flowerbig.gif",
"following": true,
"screen_name": "cindyli"
},
"source": "web",
"in_reply_to_status_id": null
},

最佳答案

将其存储在列中。然后您可以将索引放在您想要快速查找的内容上——更不用说能够搜索所有内容了。以您建议的格式搜索特定内容将是一场噩梦。

如果您想继续使用其中的位,请编写一个对象来处理它的数据库方面,或者至少编写一个将它们弹出或取出的函数。现在看起来工作量更大,但从长远来看,它会在以后为您节省很多的工作量。

编辑:是的,我会将每一位数据保存在它自己的一列中。话虽如此,您可能不需要存储所有信息。例如,如果您不想保留有关“用户提及”的信息,请完全跳过它。

编辑 2L 以正确看待这个问题,假设您想搜索“Bob”。如果您有这样的列结构:

+------+-----------+-----------+-----+
| user | favorited | truncated | url |
+------+-----------+-----------+-----+
| Bob | true | false | ... |
| Sue | true | true | ... |
| Tom | true | false | ... |
+------+-----------+-----------+-----+

您可以只编写一个死板的简单查询。

与这样的东西相比:

+--------------------------------------------------------------+
| tweetData |
+--------------------------------------------------------------+
| user:Bob;favorited:true;truncated:false;url:www.example.com |
| user:Sue;favorited:true;truncated:true;url:www.example2.com |
| user:Tom;favorited:true;truncated:false;url:www.example2.com |
+--------------------------------------------------------------+

想象一下,试图找出 Bob 被收藏了多少次。您每次都必须提取整行,进行一些操作/正则表达式/技巧来获取该字段,然后手动对其进行统计。

关于php - 有什么最好的方法可以在 MySQL 中存储推文吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11965246/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com