function TagSearch() { $per_page_num = 10; $topic_parent_disable = false; $query_link = 'index.php?mod=search&code=tag'; $tag = trim(get_param('tag')); if ($tag) { $tag = get_safe_code($tag); $tag = $this->_filterKeyword($tag); $search_keyword = $tag; $_GET['highlight'] = $search_keyword; $cache_time = 600; $cache_key = "tag-search-{$tag}"; if (false === ($topic_ids = cache_db('mget', $cache_key))) { $sql = "select `id` from `" . TABLE_PREFIX . "tag` WHERE " . build_like_query('`name`', $tag) . " ORDER BY `last_post` DESC LIMIT {$this->cache_ids_limit} "; $query = $this->DatabaseHandler->Query($sql); $tag_id = array(); while (false != ($row = $query->GetRow())) { $tag_id[$row['id']] = $row['id']; } $topic_ids = array(); if ($tag_id) { $sql = "SELECT `item_id` FROM `" . TABLE_PREFIX . "topic_tag` WHERE `tag_id` in(" . jimplode($tag_id) . ") ORDER BY `item_id` DESC LIMIT {$this->cache_ids_limit} "; $query = $this->DatabaseHandler->Query($sql); while (false != ($row = $query->GetRow())) { $topic_ids[$row['item_id']] = $row['item_id']; } } cache_db('mset', $cache_key, $topic_ids, $cache_time); } $topic_ids = filter_tids($topic_ids); if ($topic_ids) { $where = " `tid` in('" . implode("','", $topic_ids) . "') "; } $query_link .= "&tag=" . urlencode($tag); } if ($where) { $options = array('where' => $where, 'type' => get_topic_type(), 'order' => ' `dateline` desc ', 'page_url' => $query_link, 'perpage' => $per_page_num); $info = $this->TopicListLogic->get_data($options); $topic_list = array(); $total_record = 0; if (!empty($info)) { $topic_list = $info['list']; $total_record = $info['count']; $page_arr = $info['page']; } $topic_list_count = 0; if ($topic_list) { $topic_list_count = count($topic_list); if (!$topic_parent_disable) { $parent_list = $this->TopicLogic->GetParentTopic($topic_list); } } } $member = jsg_member_info(MEMBER_ID); if ($member['medal_id']) { $medal_list = $this->TopicLogic->GetMedal($member['medal_id'], $member['uid']); } $this->Title = "话题搜索"; include template('social/search_list'); }
function get_tids_by_keyword($keyword, $limit = 600, $cache_time = 300) { $tids = array(); $keyword = trim($keyword); $limit = max(0, (int) $limit); if ($keyword && $limit > 0) { $cache_time = max(15, (int) $cache_time); $cache_key = 'topic-search-' . $keyword . '-' . $limit; if (false === ($tids = cache_db('mget', $cache_key))) { $tids = jtable('topic_more')->get_ids(array('result_count' => $limit, 'sql_where' => build_like_query('`longtext`', $keyword), 'sql_order' => ' `tid` DESC '), 'tid'); $tids = (array) ($tids ? $tids : array()); cache_db('mset', $cache_key, $tids, $cache_time); } } return filter_tids($tids); }