首頁 php教程 PHP源码 使用阿里云搜索搭建强大的搜索引擎

使用阿里云搜索搭建强大的搜索引擎

May 25, 2016 pm 05:08 PM

跳至

setLifeTime(1);

$ch_url_handle = parse_url($_SERVER['REQUEST_URI']);
if ($cache->start(preg_replace("/&|=/is", '', $ch_url_handle['query'])))
    exit(0);
//@TODO 缓存文件分级
//end 缓存
include './gs_function.php';
include './class/css.class.php';
include './class/dataHelper.class.php';

$P_QUERY = mysql_escape_string($_GET['q']); // 搜索关键字
$P_TYPE = (int) mysql_escape_string($_GET['t']);
include './tpl/main_search_head.php'; // 加载页面头部
// 进行云搜索
try {
    $css_api = new CloudSearchApi();
    $param_type = array('book', 'blog', 'art', 'bbs', 'qa'); // 索引列表
    $indexName = key_exists($P_TYPE, $param_type) ? $param_type[(int) $_GET['t']] : $param_type[0]; // load索引列表 添加参数过滤
    $index = $css_api->getIndex($indexName);
    $P_PAGES_LITE = isset($_GET['pl']) ? (int) $_GET['pl'] : 15; //设置每页显示结果数
    $P_CUR_PAGES = isset($_GET['p']) ? (int) $_GET['p'] !== 0 ? (int) $_GET['p'] : 1  : 1; //GET参数过滤
    $results = $index->search('q=' . $P_QUERY, $P_CUR_PAGES, $P_PAGES_LITE); //云端执行搜索,下面是结果处理

    if (isset($results["result"]["total"]) && $results["result"]["total"] != 0) {
        //搜索返回大于0个结果 正常显示
        $R_searchtime = $results["result"]['searchtime'];
        $R_total = $P_PAGES_TOTAL = $results["result"]['total'];
        $P_SP = dataHelper::splitPages($P_PAGES_TOTAL, $P_PAGES_LITE); //获取分页总数
        //print_r($results);
        include './tpl/main_search_result.php';
        $cache->end();
    } else {
        //没结果 显示错误页面
    }
} catch (Exception $e) {
    //#TODO 添加用户自己的失败处理逻辑
}
?>
登入後複製

                   

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)