/** * 查询user列表 */ function sphinx_search2($cl, $index, $cond, $sort, $page, $pagesize, $code = 0, $offset) { global $memcached, $user_arr, $isdispmore, $isresult; $max_total = 600; $user = null; $total_found = 0; $pagenum = ceil($max_total / $pagesize); //分页数 $usersArr_unused = array(); $usersArr_used = array(); $user2 = array(); if ($page == $pagenum) { //如果是最后一页,显示指定的条数 $limit = $max_total % $pagesize; } else { //其他情况显示规定条数 $limit = $pagesize; } //$code != 0;降低查询条件 if ($code > 0) { //删除一个条件,如果属性条件都去掉则return false; $cond = DelAttr($cond, $index); //如果没有可删减的条件则返回false if (!is_array($cond) || empty($cond) || $cond == false) { return array(); } } //查询条件加缓存 $cond_str = md5(serialize($cond)); $cond_key = $user_arr['uid'] . '_' . $cond_str; $old_search = $memcached->get($cond_key); if (isset($old_search['total']) && $old_search['total'] < $offset) { if (!$old_search['total']) { $isresult = false; } $user = sphinx_search2($cl, $index, $cond, $sort, $page, $pagesize, $code + 1, $offset - $old_search['total']); } else { $rs = $cl->getResultOfReset($cond, array($offset, $pagesize), $sort); if (isset($rs['total_found']) && $rs['total_found']) { //有查询的结果 $total_found = $rs['total_found']; $rs_matches = $rs['matches']; $cond_arr = array('cond' => $cond, 'total' => $total_found); $memcached->set($cond_key, $cond_arr, false, 3600); if (!empty($rs_matches) && count($rs_matches) == 0) { //查询出0个 $user = sphinx_search2($cl, $index, $cond, $sort, $page, $pagesize, $code + 1, $offset); } elseif (!empty($rs_matches) && count($rs_matches) == $pagesize) { //查询的数目正好 //$user = $cl -> getIds(); //高级,钻石,城市之星靠前,普通和全权会员交叉显示,全权会员按照使用日期降序排序(1)*****begin****************** $cond2 = $cond; //最大600查询 if ($total_found > $max_total) { $total_found = $max_total; } //$rs=$cl -> getResultOfReset($cond2,array(0,$total_found),$sort); $users = $cl->getIdSidUType(); $user = $userGeneral = $userAdvance = array(); foreach ($users as $key => $val) { $user[] = $val['id']; //全部会员UID if ($val['s_cid'] < 40) { $userAdvance[] = $val['id']; //高级以上会员UID } else { if ($val['usertype'] != 3) { $userGeneral[] = $val['id']; } //普通会员UID } } //按照同样的数量搜索出全权会员 foreach ($cond2 as $k => $v) { if ('usertype' == $v[0]) { unset($cond2[$k]); break; } } // print_r($cond); $cond2[] = array('usertype', '3', false); //$rs2 = $cl -> getResultOfReset($cond2,array(0,$total_found),$sort); // $total_found2=$rs2['total_found']; $rs2 = $cl->getResultOfReset($cond2, array($offset, $pagesize), $sort); $total_found2 = $rs2['total_found']; $usersArr_collect = $cl->getIds(); // print_r($usersArr_collect); if (!empty($usersArr_collect) && count($usersArr_collect > 0)) { $userstr_collect = implode(',', $usersArr_collect); } else { $userstr_collect = 0; } //使用未过期的全权显示 $usetime = time() - 3888000; $sql = "select uid,action_time from web_full_log where uid in ({$userstr_collect}) order by action_time desc"; //全权会员首次使用时间降序排列 $result = $GLOBALS['_MooClass']['MooMySQL']->getAll($sql); // print_r($result); $usersArr_used = array(); if (!empty($result)) { foreach ($result as $val) { if (empty($val['action_time'])) { continue; } if ($val['action_time'] > $usetime) { $usersArr_used[] = $val['uid']; } else { $ka = array_search($val['uid'], $usersArr_collect); if ($ka) { unset($usersArr_collect[$ka]); } } } } $usersArr_unused = substractArr($usersArr_collect, $usersArr_used); $usersArr_collect2 = array_merge($usersArr_unused, $usersArr_used); $total_found2 = sizeof($usersArr_collect2); if ($total_found + $total_found2 > $max_total) { $total_found = $max_total; } else { $total_found = $total_found + $total_found2; } $userGeneral = insertArray($userGeneral, $usersArr_collect2); //普通会员中插入全权会员 $user2 = array_merge($userAdvance, $userGeneral); if (count($user2 > $max_total)) { //$user2=array_slice($user2,0,$max_total); $user2 = array_slice($user2, 0, $pagesize); } //$user2=array_slice($user2,$offset,$pagesize); $user = array_unique($user2); //高级,钻石,城市之星靠前,普通和全权会员交叉显示,全权会员按照使用日期降序排序(1)*****end****************** } else { //查询数据少了 $user = $cl->getIds(); if ($isdispmore) { $user_other = sphinx_search2($cl, $index, $cond, $sort, $page, $pagesize - count($user), $code + 1, 0); if (is_array($user_other) && !empty($user_other)) { $user = array_merge($user, $user_other); } } } } elseif (!$rs) { //无查询结果 if ($code == 0) { $isresult = false; } //无结果的话,需要缓存这次按照这个条件查询能查询出的总数 $old_search = $memcached->get($cond_key); if (isset($old_search['total']) && $old_search['total']) { $rs['total_found'] = $old_search['total']; } else { $rs = $cl->getResultOfReset($cond, null, $sort); if (!isset($rs['total_found']) || !$rs['total_found']) { $rs['total_found'] = 0; } $total_found = $rs['total_found']; if (isset($rs_matches)) { $rs_matches = $rs['matches']; } $cond_arr = array('cond' => $cond, 'total' => $total_found); $memcached->set($cond_key, $cond_arr, false, 3600); } if ($offset - $rs['total_found'] > 0) { $pro_offset = $offset - $rs['total_found']; } else { $pro_offset = 0; } $user = sphinx_search2($cl, $index, $cond, $sort, $page, $pagesize, $code + 1, $pro_offset); } } return $user; }
/** * 查询user列表 */ function sphinx_search2($cl, $index, $cond, $sort, $page, $pagesize, $code = 0, $offset) { global $memcached, $user_arr, $isdispmore, $isresult; $max_total = 600; $user = null; $total_found = 0; $pagenum = ceil($max_total / $pagesize); //分页数 if ($page == $pagenum) { //如果是最后一页,显示指定的条数 $limit = $max_total % $pagesize; } else { //其他情况显示规定条数 $limit = $pagesize; } //$code != 0;降低查询条件 if ($code > 0) { //删除一个条件,如果属性条件都去掉则return false; $cond = DelAttr($cond, $index); //如果没有可删减的条件则返回false if (!is_array($cond) || empty($cond) || $cond == false) { return array(); } } //查询条件加缓存 $cond_str = md5(serialize($cond)); $cond_key = $user_arr['uid'] . '_' . $cond_str; $old_search = $memcached->get($cond_key); if (isset($old_search['total']) && $old_search['total'] < $offset) { if (!$old_search['total']) { $isresult = false; } $user = sphinx_search2($cl, $index, $cond, $sort, $page, $pagesize, $code + 1, $offset - $old_search['total']); } else { $rs = $cl->getResultOfReset($cond, array($offset, $pagesize), $sort); if (isset($rs['total_found']) && $rs['total_found']) { //有查询的结果 $total_found = $rs['total_found']; $rs_matches = $rs['matches']; $cond_arr = array('cond' => $cond, 'total' => $total_found); $memcached->set($cond_key, $cond_arr, false, 3600); if (!empty($rs_matches) && count($rs_matches) == 0) { //查询出0个 $user = sphinx_search2($cl, $index, $cond, $sort, $page, $pagesize, $code + 1, $offset); } elseif (!empty($rs_matches) && count($rs_matches) == $pagesize) { //查询的数目正好 $user = $cl->getIds(); } else { //查询数据少了 $user = $cl->getIds(); if ($isdispmore) { $user_other = sphinx_search2($cl, $index, $cond, $sort, $page, $pagesize - count($user), $code + 1, 0); if (is_array($user_other) && !empty($user_other)) { $user = array_merge($user, $user_other); } } } } elseif (!$rs) { //无查询结果 if ($code == 0) { $isresult = false; } //无结果的话,需要缓存这次按照这个条件查询能查询出的总数 $old_search = $memcached->get($cond_key); if (isset($old_search['total']) && $old_search['total']) { $rs['total_found'] = $old_search['total']; } else { $rs = $cl->getResultOfReset($cond, null, $sort); if (!isset($rs['total_found']) || !$rs['total_found']) { $rs['total_found'] = 0; } $total_found = $rs['total_found']; if (isset($rs_matches)) { $rs_matches = $rs['matches']; } $cond_arr = array('cond' => $cond, 'total' => $total_found); $memcached->set($cond_key, $cond_arr, false, 3600); } if ($offset - $rs['total_found'] > 0) { $pro_offset = $offset - $rs['total_found']; } else { $pro_offset = 0; } $user = sphinx_search2($cl, $index, $cond, $sort, $page, $pagesize, $code + 1, $pro_offset); } } return $user; }