0

我正在编写一个社交网络,我需要一种列出最常用趋势的方法,所有状态都存储在一个内容字段中,所以我需要做的就是匹配主题标签提及,例如:#trend1 #trend2 #anothertrend

并按它们排序,有没有办法用 MySQL 做到这一点?还是我必须只用 PHP 来做这件事?

提前致谢

4

4 回答 4

3

趋势背后的数学有些复杂。机器学习可能有点过头了,但你可能需要通过一些例子来工作。

如果您使用@deadtrunk 的示例代码,您会错过最近半小时内出现的趋势;如果你以@eggyal 的例子为例,你会错过一整天都很强劲但在最后半小时内平静下来的趋势。

这个问题的经典解决方案是使用导数函数(http://en.wikipedia.org/wiki/Derivative);值得构建一个示例数据库并对此进行试验,并使您的解决方案足够灵活以随着时间的推移进行更改。

虽然您想构建一些简单的东西,但您的用户将习惯于趋势,并且如果它没有按照他们期望的方式工作,他们会认为它已经坏了。

于 2012-05-10T12:20:06.597 回答
2

You should probably extract the hash tags using PHP code, and then store them in your database separately from the content of the post. This way you'll be able to query them directly, rather then parsing the content every time you sort.

于 2012-05-10T12:03:53.343 回答
1
  1. 创建一个将主题标签与状态相关联的表。

  2. 选择最近一段时间的所有状态更新 - 例如,最后半小时 - 加入主题标签关联表并按主题标签分组。

  3. 每组中的计数是“趋势”的指示。

于 2012-05-10T12:02:15.357 回答
1

I think it is better to store tags in dedicated table and then perform queries on it. So if you have a following table layout

trend | date

You'll be able to get trends using following query:

SELECT COUNT(*), trend FROM `trends` WHERE `date` = '2012-05-10' GROUP BY trend

18  test2
7   test3
于 2012-05-10T12:03:14.790 回答