//自动补全
//不限输入汉字的前后顺序: 输入"国三杀" => 输出 "三国杀"
function getAutoComplate()
{
//$word = $this->input->post('word');
$word = '三国';
if (empty($word)) {
exit('0');
}
$intWordLength = mb_strlen($word, 'UTF-8');
$this->load->library('iredis');
if (1 == $intWordLength) {
$arrGid = $this->iredis->getAutoComplate($word);
} else {
$arrGid = array();
for ($i=0; $i < $intWordLength; $i++) {
$strOne = mb_substr($word, $i, 1, 'UTF-8');
$arrGidTmp = $this->iredis->getAutoComplate($strOne);
$arrGid = empty($arrGid) ? $arrGidTmp : array_intersect($arrGid, $arrGidTmp); //求交集,因为传入的参数个数不确定,因此不能直接求交集
}
}
$arrGame = $this->gamemodel->getGameNameForAutoComplate($arrGid);
// var_dump($arrGame);exit;
$jsonGame = json_encode($arrGame);
exit($jsonGame);
}
//自动补全, 建立索引
function setAutoComplate()
{
$arrGame = $this->gamemodel->getAllGameNameForAutoComplate();
$arrIndex = array();
foreach ($arrGame as $gid => $gname) {
$intGnameLength = mb_strlen($gname, 'UTF-8');
for ($i=0; $i < $intGnameLength; $i++) {
$strOne = mb_substr($gname, $i, 1, 'UTF-8');
$arrIndex[$strOne][] = $gid;
}
}
$this->load->library('iredis');
foreach ($arrIndex as $word => $arrGid) {
foreach ($arrGid as $gid) {
$this->iredis->setAutoComplate($word, $gid);
}
}
}
//自动补全功能
public function setAutoComplate($key, $value)
{
$youxikey = 'youxi_'.$key;
$this->sAdd($youxikey, $value);
}
//自动补全功能
public function getAutoComplate($key)
{
$youxikey = 'youxi_'.$key;
return $this->sMembers($youxikey);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有