/** * 关键词搜索 */ public function init() { //获取siteid $siteid = isset($_REQUEST['siteid']) && trim($_REQUEST['siteid']) ? intval($_REQUEST['siteid']) : 1; $SEO = seo($siteid); //搜索配置 $search_setting = getcache('search'); $setting = $search_setting[$siteid]; $search_model = getcache('search_model_' . $siteid); $type_module = getcache('type_module_' . $siteid); if (isset($_GET['q'])) { if (trim($_GET['q']) == '') { header('Location: ' . APP_PATH . 'index.php?m=search'); exit; } $typeid = empty($_GET['typeid']) ? 48 : intval($_GET['typeid']); $time = empty($_GET['time']) || !in_array($_GET['time'], array('all', 'day', 'month', 'year')) ? 'all' : trim($_GET['time']); $page = isset($_GET['page']) ? intval($_GET['page']) : 1; $pagesize = 10; $q = safe_replace(trim($_GET['q'])); $q = htmlspecialchars(strip_tags($q)); $q = str_replace('%', '', $q); //过滤'%',用户全文搜索 $search_q = $q; //搜索原内容 //按时间搜索 if ($time == 'day') { $search_time = SYS_TIME - 86400; $sql_time = ' AND adddate > ' . $search_time; } elseif ($time == 'week') { $search_time = SYS_TIME - 604800; $sql_time = ' AND adddate > ' . $search_time; } elseif ($time == 'month') { $search_time = SYS_TIME - 2592000; $sql_time = ' AND adddate > ' . $search_time; } elseif ($time == 'year') { $search_time = SYS_TIME - 31536000; $sql_time = ' AND adddate > ' . $search_time; } else { $search_time = 0; $sql_time = ''; } if ($page == 1 && !$setting['sphinxenable']) { //精确搜索 $commend = $this->db->get_one("`typeid` = '{$typeid}' {$sql_time} AND `data` like '%{$q}%'"); } else { $commend = ''; } //如果开启sphinx if ($setting['sphinxenable']) { $sphinx = pc_base::load_app_class('search_interface', '', 0); $sphinx = new search_interface(); $offset = $pagesize * ($page - 1); $res = $sphinx->search($q, array($siteid), array($typeid), array($search_time, SYS_TIME), $offset, $pagesize, '@weight desc'); $totalnums = $res['total']; //如果结果不为空 if (!empty($res['matches'])) { $result = $res['matches']; } } else { pc_base::load_sys_class('segment', '', 0); $segment = new segment(); //分词结果 $segment_q = $segment->get_keyword($segment->split_result($q)); //如果分词结果为空 if (!empty($segment_q)) { $sql = "`siteid`= '{$siteid}' AND `typeid` = '{$typeid}' {$sql_time} AND MATCH (`data`) AGAINST ('{$segment_q}' IN BOOLEAN MODE)"; } else { $sql = "`siteid`= '{$siteid}' AND `typeid` = '{$typeid}' {$sql_time} AND `data` like '%{$q}%'"; } $result = $this->db->listinfo($sql, 'searchid DESC', $page, 10); } //如果开启相关搜索功能 if ($setting['relationenble']) { //如果关键词长度在8-16之间,保存关键词作为relation search $this->keyword_db = pc_base::load_model('search_keyword_model'); if (strlen($q) < 17 && strlen($q) > 5 && !empty($segment_q)) { $res = $this->keyword_db->get_one(array('keyword' => $q)); if ($res) { //关键词搜索数+1 //$this->keyword_db->update(array('searchnums'=>'+=1'), array('keyword'=>$q)); } else { //关键词转换为拼音 pc_base::load_sys_func('iconv'); $pinyin = gbk_to_pinyin($q); if (is_array($pinyin)) { $pinyin = implode('', $pinyin); } $this->keyword_db->insert(array('keyword' => $q, 'searchnums' => 1, 'data' => $segment_q, 'pinyin' => $pinyin)); } } //相关搜索 if (!empty($segment_q)) { $relation_q = str_replace(' ', '%', $segment_q); } else { $relation_q = $q; } $relation = $this->keyword_db->select("MATCH (`data`) AGAINST ('%{$relation_q}%' IN BOOLEAN MODE)", '*', 10, 'searchnums DESC'); } //如果结果不为空 if (!empty($result) || !empty($commend['id'])) { //开启sphinx后文章id取法不同 if ($setting['sphinxenable']) { foreach ($result as $_v) { $sids[] = $_v['attrs']['id']; } } else { foreach ($result as $_v) { $sids[] = $_v['id']; } } if (!empty($commend['id'])) { $sids[] = $commend['id']; } $sids = array_unique($sids); $where = to_sqls($sids, '', 'id'); //获取模型id $model_type_cache = getcache('type_model_' . $siteid, 'search'); $model_type_cache = array_flip($model_type_cache); $modelid = $model_type_cache[$typeid]; //是否读取其他模块接口 if ($modelid) { $this->content_db->set_model($modelid); /** * 如果表名为空,则为黄页模型 */ if (empty($this->content_db->model_tablename)) { $this->content_db = pc_base::load_model('yp_content_model'); $this->content_db->set_model($modelid); } if ($setting['sphinxenable']) { $data = $this->content_db->listinfo($where, 'id DESC', 1, $pagesize); $pages = pages($totalnums, $page, $pagesize); } else { $data = $this->content_db->select($where, '*'); $pages = $this->db->pages; $totalnums = $this->db->number; } //如果分词结果为空 if (!empty($segment_q)) { $replace = explode(' ', $segment_q); foreach ($replace as $replace_arr_v) { $replace_arr[] = '<font color=red>' . $replace_arr_v . '</font>'; } foreach ($data as $_k => $_v) { $data[$_k]['title'] = str_replace($replace, $replace_arr, $_v['title']); $data[$_k]['description'] = str_replace($replace, $replace_arr, $_v['description']); } } else { foreach ($data as $_k => $_v) { $data[$_k]['title'] = str_replace($q, '<font color=red>' . $q . '</font>', $_v['title']); $data[$_k]['description'] = str_replace($q, '<font color=red>' . $q . '</font>', $_v['description']); } } } else { //读取专辑搜索接口 $special_api = pc_base::load_app_class('search_api', 'special'); $data = $special_api->get_search_data($sids); $totalnums = count($data); } } $execute_time = execute_time(); $pages = isset($pages) ? $pages : ''; $totalnums = isset($totalnums) ? $totalnums : 0; $data = isset($data) ? $data : ''; include template('search', 'list'); } else { include template('search', 'index'); } }
public function search() { $this->db = pc_base::load_model('search_model'); $q = safe_replace(trim($_POST['title'])); $typeid = isset($_GET['typeid']) ? intval($_GET['typeid']) : 58; $siteid = isset($_GET['siteid']) ? intval($_GET['siteid']) : 1; $page = isset($_GET['page']) ? intval($_GET['page']) : 1; $q = htmlspecialchars(strip_tags($q)); $q = str_replace('%', '', $q); // 过滤'%',用户全文搜索 $search_q = $q; // 搜索原内容 $time = empty($_GET['time']) || !in_array($_GET['time'], array('all', 'day', 'month', 'year')) ? 'all' : trim($_GET['time']); if ($time == 'day') { $search_time = SYS_TIME - 86400; $sql_time = ' AND adddate > ' . $search_time; } elseif ($time == 'week') { $search_time = SYS_TIME - 604800; $sql_time = ' AND adddate > ' . $search_time; } elseif ($time == 'month') { $search_time = SYS_TIME - 2592000; $sql_time = ' AND adddate > ' . $search_time; } elseif ($time == 'year') { $search_time = SYS_TIME - 31536000; $sql_time = ' AND adddate > ' . $search_time; } else { $search_time = 0; $sql_time = ''; } if ($page == 1 && !$setting['sphinxenable']) { // 精确搜索 $commend = $this->db->get_one("`typeid` = '{$typeid}' {$sql_time} AND `data` like '%{$q}%'"); } else { $commend = ''; } pc_base::load_sys_class('segment', '', 0); $segment = new segment(); // 分词结果 $segment_q = $segment->get_keyword($segment->split_result($q)); // 如果分词结果为空 if (!empty($segment_q)) { $sql = "`siteid`= '{$siteid}' AND `typeid` = '{$typeid}' {$sql_time} AND MATCH (`data`) AGAINST ('{$segment_q}' IN BOOLEAN MODE)"; } else { $sql = "`siteid`= '{$siteid}' AND `typeid` = '{$typeid}' {$sql_time} AND `data` like '%{$q}%'"; } $result = $this->db->listinfo($sql, 'searchid DESC', $page, 7); if (!empty($result) || !empty($commend['id'])) { //开启sphinx后文章id取法不同 if ($setting['sphinxenable']) { foreach ($result as $_v) { $sids[] = $_v['attrs']['id']; } } else { foreach ($result as $_v) { $sids[] = $_v['id']; } } if (!empty($commend['id'])) { $sids[] = $commend['id']; } $sids = array_unique($sids); $where = to_sqls($sids, '', 'id'); //获取模型id $model_type_cache = getcache('type_model_' . $siteid, 'search'); $model_type_cache = array_flip($model_type_cache); $modelid = $model_type_cache[$typeid]; //是否读取其他模块接口 if ($modelid) { $this->content_db->set_model($modelid); /** * 如果表名为空,则为黄页模型 */ if (empty($this->content_db->model_tablename)) { $this->content_db = pc_base::load_model('yp_content_model'); $this->content_db->set_model($modelid); } if ($setting['sphinxenable']) { $data = $this->content_db->listinfo($where, 'id DESC', 1, $pagesize); $pages = wpa_pages($totalnums, $page, $pagesize); } else { $data = $this->content_db->select($where, '*'); $pages = $this->db->pages; $totalnums = $this->db->number; } //如果分词结果为空 if (!empty($segment_q)) { $replace = explode(' ', $segment_q); foreach ($replace as $replace_arr_v) { $replace_arr[] = '<font color=red>' . $replace_arr_v . '</font>'; } foreach ($data as $_k => $_v) { $data[$_k]['title'] = str_replace($replace, $replace_arr, $_v['title']); $data[$_k]['description'] = str_replace($replace, $replace_arr, $_v['description']); } } else { foreach ($data as $_k => $_v) { $data[$_k]['title'] = str_replace($q, '<font color=red>' . $q . '</font>', $_v['title']); $data[$_k]['description'] = str_replace($q, '<font color=red>' . $q . '</font>', $_v['description']); } } } else { //读取专辑搜索接口 $special_api = pc_base::load_app_class('search_api', 'special'); $data = $special_api->get_search_data($sids); $totalnums = count($data); } } $execute_time = execute_time(); $totalnums = isset($totalnums) ? $totalnums : 0; $totalpage = $totalnums / 7; $pagesi = wpa_pages($totalpage, $page, 7); $data = isset($data) ? $data : ''; include template('wap', 'list_search'); }
foreach ($info as $k => $val) { echo '<li style="border-bottom:1px solid #EEE;font-size:14px;padding:0 12px">' . (is_numeric($k) ? '' : $k . ' : ') . htmlentities($val, ENT_COMPAT, 'utf-8') . '</li>'; } } ?> </ol> </div> <?php } ?> </div> </div> <div id="leaps_page_trace_close" style="display:none;text-align:right;height:15px;position:absolute;top:10px;right:12px;cursor: pointer;"><img style="vertical-align:top;" src="data:image/gif;base64,R0lGODlhDwAPAJEAAAAAAAMDA////wAAACH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjAgNjEuMTM0Nzc3LCAyMDEwLzAyLzEyLTE3OjMyOjAwICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MUQxMjc1MUJCQUJDMTFFMTk0OUVGRjc3QzU4RURFNkEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MUQxMjc1MUNCQUJDMTFFMTk0OUVGRjc3QzU4RURFNkEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDoxRDEyNzUxOUJBQkMxMUUxOTQ5RUZGNzdDNThFREU2QSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDoxRDEyNzUxQUJBQkMxMUUxOTQ5RUZGNzdDNThFREU2QSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PgH//v38+/r5+Pf29fTz8vHw7+7t7Ovq6ejn5uXk4+Lh4N/e3dzb2tnY19bV1NPS0dDPzs3My8rJyMfGxcTDwsHAv769vLu6ubi3trW0s7KxsK+urayrqqmop6alpKOioaCfnp2cm5qZmJeWlZSTkpGQj46NjIuKiYiHhoWEg4KBgH9+fXx7enl4d3Z1dHNycXBvbm1sa2ppaGdmZWRjYmFgX15dXFtaWVhXVlVUU1JRUE9OTUxLSklIR0ZFRENCQUA/Pj08Ozo5ODc2NTQzMjEwLy4tLCsqKSgnJiUkIyIhIB8eHRwbGhkYFxYVFBMSERAPDg0MCwoJCAcGBQQDAgEAACH5BAAAAAAALAAAAAAPAA8AAAIdjI6JZqotoJPR1fnsgRR3C2jZl3Ai9aWZZooV+RQAOw==" /></div> </div> <div id="leaps_page_trace_open" style="height:30px;float:right;text-align: right;overflow:hidden;position:fixed;bottom:0;right:0;color:#000;line-height:30px;cursor:pointer;"><div style="background:#232323;color:#FFF;padding:0 6px;float:right;line-height:30px;font-size:14px"><?php echo execute_time() . 's '; ?> </div> <img width="150" style="" title="ShowPageTrace" src="data:image/png;base64,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"></div> <script type="text/javascript"> (function(){ var tab_tit = document.getElementById('leaps_page_trace_tab_tit').getElementsByTagName('span'); var tab_cont = document.getElementById('leaps_page_trace_tab_cont').getElementsByTagName('div'); var open = document.getElementById('leaps_page_trace_open'); var close = document.getElementById('leaps_page_trace_close').childNodes[0]; var trace = document.getElementById('leaps_page_trace_tab'); var cookie = document.cookie.match(/leaps_show_page_trace=(\d\|\d)/); var history = (cookie && typeof cookie[1] != 'undefined' && cookie[1].split('|')) || [0,0]; open.onclick = function(){ trace.style.display = 'block'; this.style.display = 'none';
/** * 关键词搜索 */ public function init() { //获取siteid $siteid = isset($_REQUEST['siteid']) && trim($_REQUEST['siteid']) ? intval($_REQUEST['siteid']) : 1; $SEO = seo($siteid); //搜索配置 $search_setting = getcache('search'); $setting = $search_setting[$siteid]; $search_model = getcache('search_model_' . $siteid); $type_module = getcache('type_module_' . $siteid); if (isset($_POST['q'])) { if (trim($_POST['q']) == '') { header('Location: ' . APP_PATH . 'index.php?m=search'); exit; } $typeid = empty($_POST['typeid']) ? 0 : intval($_POST['typeid']); $time = empty($_POST['time']) || !in_array($_POST['time'], array('all', 'day', 'month', 'year', 'week')) ? 'all' : trim($_POST['time']); $page = isset($_POST['page']) ? intval($_POST['page']) : 1; $pagesize = 10; $q = safe_replace(trim($_POST['q'])); $q = new_html_special_chars(strip_tags($q)); $q = str_replace('%', '', $q); //过滤'%',用户全文搜索 $search_q = $q; //搜索原内容 $sql_time = $sql_tid = ''; if ($typeid) { $sql_tid = ' AND typeid = ' . $typeid; } //按时间搜索 if ($time == 'day') { $search_time = SYS_TIME - 86400; $sql_time = ' AND adddate > ' . $search_time; } elseif ($time == 'week') { $search_time = SYS_TIME - 604800; $sql_time = ' AND adddate > ' . $search_time; } elseif ($time == 'month') { $search_time = SYS_TIME - 2592000; $sql_time = ' AND adddate > ' . $search_time; } elseif ($time == 'year') { $search_time = SYS_TIME - 31536000; $sql_time = ' AND adddate > ' . $search_time; } else { $search_time = 0; $sql_time = ''; } if ($page == 1 && !$setting['sphinxenable']) { //精确搜索 $commend = $this->db->get_one("`siteid`= '{$siteid}' {$sql_tid} {$sql_time} AND `data` like '%{$q}%'"); } else { $commend = ''; } //如果开启sphinx if ($setting['sphinxenable']) { $sphinx = pc_base::load_app_class('search_interface', '', 0); $sphinx = new search_interface(); $offset = $pagesize * ($page - 1); $res = $sphinx->search($q, array($siteid), array($typeid), array($search_time, SYS_TIME), $offset, $pagesize, '@weight desc'); $totalnums = $res['total']; //如果结果不为空 if (!empty($res['matches'])) { $result = $res['matches']; } } else { $sql = "`siteid`= '{$siteid}' {$sql_tid} {$sql_time} AND `data` like '%{$q}%'"; $result = $this->db->listinfo($sql, 'searchid DESC', $page, 10); //$result = $this->db->listinfo($sql, 'adddate ASC', $page, 10); } //如果结果不为空 if (!empty($result) || !empty($commend['id'])) { foreach ($result as $_v) { if ($_v['typeid']) { $sids[$_v['typeid']][] = $_v['id']; } } if (!empty($commend['id'])) { if ($commend['typeid']) { $sids[$commend['typeid']][] = $commend['id']; } } $model_type_cache = getcache('type_model_' . $siteid, 'search'); $model_type_cache = array_flip($model_type_cache); $data = array(); foreach ($sids as $_k => $_val) { $tid = $_k; $ids = array_unique($_val); $where = to_sqls($ids, '', 'id'); //获取模型id $modelid = $model_type_cache[$tid]; //是否读取其他模块接口 if ($modelid) { $this->content_db->set_model($modelid); /** * 如果表名为空,则为黄页模型 */ if (empty($this->content_db->model_tablename)) { $this->content_db = pc_base::load_model('yp_content_model'); $this->content_db->set_model($modelid); } $datas = $this->content_db->select($where, '*', '', 'inputtime DESC'); } $data = array_merge($data, $datas); } $pages = $this->db->pages; $totalnums = $this->db->number; //如果分词结果为空 if (!empty($segment_q)) { $replace = explode(' ', $segment_q); foreach ($replace as $replace_arr_v) { $replace_arr[] = '' . $replace_arr_v . ''; } foreach ($data as $_k => $_v) { $data[$_k]['title'] = str_replace($replace, $replace_arr, $_v['title']); $data[$_k]['description'] = str_replace($replace, $replace_arr, $_v['description']); } } else { foreach ($data as $_k => $_v) { $data[$_k]['title'] = str_replace($q, '' . $q . '', $_v['title']); $data[$_k]['description'] = str_replace($q, '' . $q . '', $_v['description']); } } } $execute_time = execute_time(); $pages = isset($pages) ? $pages : ''; $totalnums = isset($totalnums) ? $totalnums : 0; $data = isset($data) ? $data : ''; include template('search', 'list'); } else { include template('search', 'index'); } }
/** * 显示运行时间、数据库操作、缓存次数、内存使用信息 * * @return string */ function show_time() { if (!C('config', 'show_time')) { return; } $show_time = ''; // 显示运行时间 $show_time = 'Process: ' . execute_time() . ' seconds '; if (class_exists('Core_DB', false)) { $show_time .= ' | DB :' . N('db_query') . ' queries '; } $show_time .= ' | Cache :' . N('cache_read') . ' gets ' . N('cache_write') . ' writes '; // 显示内存开销 $startMem = array_sum(explode(' ', START_MEMORY)); $endMem = array_sum(explode(' ', memory_get_usage())); $show_time .= ' | UseMem:' . number_format(($endMem - $startMem) / 1024) . ' kb'; if (IS_CLI) { return "\r\n" . $show_time . "\r\n"; } return $show_time; }