创建提到像Twitter或PHP convore [英] create mention like twitter or convore with php

查看:117
本文介绍了创建提到像Twitter或PHP convore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我只是好奇。他们如何做的东西。我认为他们做这样的事情。

  @ someone1即时堆叠在计算器RT @ someone2:好家伙你在做什么?

我做我的方式之前,我想告诉你我的数据库架构

  // CID =评论ID,BID = BLOG ID,UID =用户标识
CID BID UID COMMENT
1 1 1 @ someone1即时堆叠在计算器RT @ someone2:....
2 1 4 @ someone1即时堆叠在计算器RT @ someone2:....
3 1 12 @ someone1即时堆叠在计算器RT @ someone2:....


  1. 他们用正则表达式做这样拿@someones名称

      preg_match_all(/ @ [A-ZA-Z0-9 _] + /,$文字,$匹配);


  2. 那么他们得到的@关每个名称

     的foreach($的匹配,$值){
    的foreach($值$值){
        $用户名[] = SUBSTR($值,1);
    }
    }


  3. 然后他们从做这样的事情从数据库中获取的UID

     的foreach($用户名作为$值){
    #插入数据库逐一?所以这将是象上面的例子
    }


然后我们就可以输出注释买歌厅的UID。

然后somhow我们可以得到在博客的所有评论。 (无同评论),其中博客打造专业化= 1 其中uid =给他们中的每个用户一个通知:UID

有没有更好的办法这样做呢?像Twitter或convore?

感谢您寻找在

亚当斋月


解决方案

我已经做了一些类似的与我们用于通信的内部应用程序。

基本上,你将有两个表: status_updates的提到。每个状态更新有许多提及。每当有人创建了一个状态更新,将其保存到 status_updates的表。在这个过程中,你也可以使用正则表达式来检测任何 @username 提到了。当你找到一提的,你把它添加到您的提到表。例如,你的提到表可能是这个样子:

  mention_id(自动递增键)| status_message_id | username_id

这样,如果你想看看是否有人在状态消息中提到,你可以做在 status_messages 表快速查找,而不是加载了状态消息和运行的Regex各一次。这种方法的另一好处是,它可以让你在每个状态消息的多个提及。只需要在的纪录提到每个

这是基本的方法,我们已经对其进行设置。

编辑:如果你想拉一活动进给定用户,只显示在他们所提到的状态更新,这将是简单的:

  SELECT * FROM提到m左侧JOIN status_messages S于m.status_message_id = s.id WHERE m.username_id = $ username_id

我要指出,这是不是他们是如何做到的微博,因为他们正在处理的规模问题,这将使做的事情是不可能的这种简单方式。不过,我认为这是,如果你不担心扩展到数十万用户的行之有效的简单的解决方案。如果你是,那么你可能对你的手比这更多的问题。

hello im just curious. about how they do stuff. what i assume they do something like this

@someone1 im stacking on stackoverflow RT @someone2 : hello guys what are you doing?

before i do it in my way i want to tell you about my database scheme

// CID = COMMENT ID, BID  = BLOG ID, UID = USER ID
CID    BID   UID    COMMENT
1       1     1      @someone1 im stacking on stackoverflow RT @someone2 : ....
2       1     4      @someone1 im stacking on stackoverflow RT @someone2 : ....
3       1     12     @someone1 im stacking on stackoverflow RT @someone2 : ....

  1. they use regex to do like this to take the @someones name

    preg_match_all("/@[a-zA-Z0-9_]+/", $text, $matches);
    

  2. then they get the @ off each name

    foreach ($matches as $value) {
    foreach ($value as $value) {
        $usernames[] = substr($value, 1);
    }
    }
    

  3. then they get the UID from the database from doing something like this

    foreach ($username as $value) {
    # insert database one by one ? so it will be like the example above
    }
    

then we can just output the comment buy geting the UID.

then somhow we can get all the comments in the blog. ( without a same comment ) where blog buid = 1 and give them an notification on every user by where uid = :uid.

is there any better way doing this ? something like twitter or convore ?

Thanks for looking in

Adam Ramadhan

解决方案

I have done something similar to this with an in-house application that we use for communication.

Basically, you are going to have two tables: status_updates and mentions. Each status update has many mentions. Whenever someone creates a status update, you save it to the status_updates table. During this process, you can also use Regex to detect any @username "mentions". When you find a mention, you add it to your mentions table. For example, your mentions table might look something like this:

 mention_id (Auto-incrementing key) | status_message_id | username_id

That way if you want to see if someone is mentioned in a status message you can do a quick lookup in the status_messages table, as opposed to loading up the status message and running the Regex each time. The other nice thing about this approach is that it allows you to have multiple mentions in each status message. Just create a record in mentions for each.

That's the basic way that we have set it up.

EDIT: If you wanted to pull an "activity feed" for a given user, showing only the status updates in which they have been mentioned, it would be as simple as:

SELECT * FROM mentions m LEFT JOIN status_messages s ON m.status_message_id = s.id WHERE m.username_id = $username_id

I should note that this is not how they do it at Twitter, because they are dealing with issues of scale that would make this simple way of doing things impossible. However, I think this is the simplest solution that works well if you aren't worried about scaling to hundreds of thousands of users. If you are, then you probably have more issues on your hands than this.

这篇关于创建提到像Twitter或PHP convore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆