繁体   English   中英

PHP,MYSQL,JSOn社交网站的快速搜索功能提示

[英]PHP, MYSQL,JSOn Fast search functionality tips for social networking website

嗨,我正在开发社交网站,需要一个建议。 我正在使用codeignitor框架,php作为核心语言,而jQuery作为客户端脚本。

现在,我想在用户可以搜索其他用户的网站上实现用户搜索功能。

如果我使用php分页,速度会有点慢,性能也不会很快,即使数据库很大,速度也会更慢。

所以我尝试的是,我使用此插件http://www.stephenrhoades.com/?p=8,对前1000个人进行了查询,并使用json进行了编码,并一次显示了前10个结果

有谁能帮助我在这里我需要遵循的所有内容,包括技术,技巧,查询,mysql数据库等。

这是我目前在模型中的功能

    function search_user($cntry,$male,$female,$age_min,$age_max){

               $this->db->select('user_profiles.user_id,user_profiles.first_name,
               user_profiles.birthday,user_profiles.gender,user_profiles.picture,
               user_profiles.last_active,location.city,location.country');

     $this->db->from('user_profiles');

     $this->db->join('location', 'user_profiles.user_id = location.user_id');

     $this->db->limit(800);


    // Search condition :::: Country 

    if($cntry){
    $this->db->like('location.country',$cntry, 'both');
    }

    // Search condition :::: Male or Female 

     if($male==1 && $female==0) {  $g='Male'; $this->db->like('user_profiles.gender',$g, 'both');  }

     if($male==0 && $female==1) {  $g='Female'; $this->db->like('user_profiles.gender',$g, 'both');  }

     // Search condition :::: Age range
     if($age_min && !$age_max){

        $this->db->where('(YEAR(NOW())-YEAR(user_profiles.birthday)) >= ', $age_min);
     }


     if($age_min && $age_max){

        $this->db->where('(YEAR(NOW())-YEAR(user_profiles.birthday)) >= ', $age_min); 
        $this->db->where('(YEAR(NOW())-YEAR(user_profiles.birthday)) <= ', $age_max); 
     }


     $this->db->order_by("user_profiles.last_active", "desc"); 
     $query = $this->db->get();


     $data=array();
     foreach ($query->result() as $row){     
     $row->last_active=$this->online_status($row->last_active);
     $row->birthday=$this->birthday($row->birthday);
     $data[]=$row;
     }


    if ($query->num_rows() > 0)
    {
    return $data;
    }
    else
    {
    $data = array(
                'result' =>'404'
                 );
    return $data; 
    }


}

提前致谢

有许多因素可能导致此过程缓慢。 这些是我们需要解决的问题:

  • 您正在数据库中搜索哪些列?
  • 这些列被索引了吗?
  • 您的查询是什么样的? 您只返回必要的列吗?
  • 您想多快显示一次结果? 立即作为用户类型输入,还是在他们单击“搜索”之后?
  • 您如何返回结果?
  • 您如何显示结果?

通常,您可以在几毫秒内搜索非常大的数据集-因此,只要您正确设置了内容,我就怀疑数据库是否存在问题。

好吧,话虽这么说...

如果您确实有一个非常大型的社交网络,我建议您实施Zend Search Lucene之类的工具 它是一个搜索索引,可以很容易地实现到CodeIgniter中:

http://www.cmjackson.net/2009/02/17/how-to-use-zend_search_lucene-with-the-php-framework-codeigniter/

您可以将用户,他们的个人资料数据,帖子,评论等添加到索引中,并使用功能强大的语言处理查询语言对其进行搜索,并以所需的任何格式快速返回结果。 使用ajax和json转换为“实时”搜索非常容易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM