public function get_condition() { $condition = ''; if ($this->input['search_text']) { include ROOT_PATH . 'lib/class/pinyin.class.php'; $title_pinyin_result = hanzi_to_pinyin($this->input['search_text'], false, 0); if ($title_pinyin_result['word']) { $pinyin = implode('', $title_pinyin_result['word']); $condition .= ' AND pinyin like "%' . $pinyin . '%"'; //$title = $this->get_titleResult($title . ' '); //$condition .= " AND MATCH (pinyin) AGAINST ('" . $pinyin . "' IN BOOLEAN MODE )"; //$this->other_field = ",MATCH (pinyin) AGAINST ('" . $pinyin . "' IN BOOLEAN MODE ) AS pinyin_score"; } /** else { $condition .= ' name like "%'.$this->input['search_text'].'%"'; } */ } $condition .= " ORDER BY " . ($this->other_field ? ' pinyin_score DESC,' : ''); if ($this->input['sort_type'] == 'ASC') { $condition .= " order_id " . $this->input['sort_type']; } else { $condition .= " order_id DESC "; } return $condition; }
public function show() { try { include_once CUR_CONF_PATH . 'lib/xunsearch/XS.php'; $conf = realpath(CUR_CONF_PATH . 'data/publishcontent_publishcontent.ini'); $xs = new XS($conf); // 建立 XS 对象 $search = $xs->search; // 获取 搜索对象 } catch (XSException $e) { $this->errorOutput('ERROR'); } $hotwords = $search->getHotQuery(200, 'curnum'); $words = array(); if ($hotwords) { foreach ($hotwords as $w => $r) { preg_match_all("/[\\x{4e00}-\\x{9fa5}]+/u", $w, $t); if ($t && $t[0][0] && strlen($t[0][0]) > 4) { $words[$t[0][0]] = $r; } } } if ($words) { $sql = "select id,name from " . DB_PREFIX . "hotwords where name IN ( '" . implode("','", array_keys($words)) . "')"; $q = $this->db->query($sql); $exists = array(); while ($r = $this->db->fetch_array($q)) { $exists[$r['name']] = $r['id']; } include ROOT_PATH . 'lib/class/pinyin.class.php'; include CUR_CONF_PATH . 'lib/hotwords.class.php'; $obj = new Hotwords(); foreach ($words as $w => $r) { if ($exists[$w]) { $sql = 'UPDATE ' . DB_PREFIX . 'hotwords SET rate=' . intval($r) . ' WHERE id=' . $exists[$w]; $this->db->query($sql); } else { $info = array('name' => $w, 'rate' => $r, 'user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'ip' => $this->user['ip'], 'update_time' => TIMENOW, 'create_time' => TIMENOW); $title_pinyin_result = hanzi_to_pinyin($w, false, 0); if ($title_pinyin_result['word']) { $info['pinyin'] = implode('', $title_pinyin_result['word']); } $obj->create($info); } } } }
public function update() { $name = $this->input['name']; if (!$name) { $return = array('error' => '请填热词名称'); $this->addItem($return); $this->output(); exit; } $info = array('id' => intval($this->input['id']), 'name' => $name, 'update_time' => TIMENOW); include ROOT_PATH . 'lib/class/pinyin.class.php'; $title_pinyin_result = hanzi_to_pinyin($name, false, 0); if ($title_pinyin_result['word']) { $info['pinyin'] = implode('', $title_pinyin_result['word']); } $ret = $this->obj->update($info); $return = array('success' => true, 'id' => $this->input['id']); $this->addItem($return); $this->output(); }
function get_spell_title($title) { include CUR_CONF_PATH . 'lib/pinyin.class.php'; $title_pinyin_result = hanzi_to_pinyin($title, false, 0); $title_pinyin_str = implode('', $title_pinyin_result['first_word']); //$title_pinyin_str .= ' ' . implode('', $title_pinyin_result['word']); return $title_pinyin_str; }