dousi1097 2011-03-08 04:48
浏览 12

如何加快搜索建议

I want to make a search suggestion like Google that's fast. I tried it with AJAX/jQuery, but its speed was very slow. I also tried with XML instead of MySQL, but it was slow too. How can I speed it up? my jquery code is:

function lookup(inputString,fname,sbox,asbox) {
    if(inputString.length == 0) {
        // Hide the suggestion box.
        $('#'+sbox).hide();
    } else {
        // post data to our php processing page and if there is a return greater than zero
        // show the suggestions box
        $.post(fname, {mysearchString: ""+inputString+""}, function(data){
            if(data.length >0) {
                $('#'+sbox).show();
                $('#'+asbox).html(data);
            }
        });
    }
}

and php code is

query : SELECT maincatid,category FROM maincategory WHERE category LIKE '%$mysearchString%' LIMIT 10"

        if($rs) {
            while ($result = @mysql_fetch_object($rs)) 
            {
                echo '<li onClick="fill(\''.$result->maincatid.'\',\''.$result->category.'\');">'.str_ireplace($mysearchString,'<span style="background-color:#C1E0FF;">'.$mysearchString.'</span>',$result->category).'</li>';
                $c++;
            }
        } 
        else {
            echo 'ERROR: There was a problem with the query.';
        }
    }
    } else {
    } 
} else {
    echo 'Access denied.';
}
  • 写回答

3条回答 默认 最新

  • dpdkqls6399 2011-03-08 05:35
    关注

    There are lots of reasons google's search results will be faster than yours.

    Off the top of my head,

    1. They would have some sort of optimized data warehouse with indexes and full text search instead of the free version of MySQL

    2. They don't have just one server that serves their request, they'd have a CDN and server clusters and you'd hit the server nearest you for low latency

    3. They'd have the current trending queries cached so they wouldn't have to look it up everytime you hit it.

    4. They'd be running on their own dedicated servers that do nothing but serve your search results every day instead of a shared server with a bunch of other people on it

    Forget about trying to match google. Find out where your search is slow and fix that. Install firebug and see how long your server takes to respond. Profile your code to see what parts are slow. Most of the time it's badly designed tables and slow servers that are the cause

    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch