/** * * @param type $word * @return type */ public function letterHotWordsBatch($word) { //获取字母所对应的数据 $letter_list = range('A', 'Z'); //根据随机的记录id获取需要展示的记录数组 $queries = []; $max_page = 100; for ($i = 1; $i <= 26; $i++) { $queries[] = array('word' => $word, 'indexer' => 'index_9939_com_v2_keywords_all', 'offset' => 0, 'size' => $max_page, 'condition' => array(array('filter' => 'filter', 'args' => array('pinyin_initial_sn', array($i))))); } $all_word_ids = SearchHelper::batchSearch($queries); $arr_ids = array(); foreach ($all_word_ids as $k => $ret) { if (!empty($ret['matches'])) { foreach ($ret['matches'] as $kk => $kv) { $arr_ids[] = $kk; } } } $wd_obj = new KeyWords(); $result = $wd_obj->List_ByIds($arr_ids); $return_list = []; if (!empty($result)) { $cache_rand_words = []; //把查找出的所有结果按字母放入数组 foreach ($result as $k => $v) { $caption = $v['pinyin_initial']; if (!isset($cache_rand_words[$caption])) { $cache_rand_words[$caption] = []; } $cache_rand_words[$caption][] = $v; } $len = count($letter_list); $max_dis_length = 28; for ($i = 0; $i < $len; $i++) { $wd = strtoupper($letter_list[$i]); $ret = isset($cache_rand_words[$wd]) ? $cache_rand_words[$wd] : array(); if (count($ret) > 0) { $rand_num = count($ret) > $max_dis_length ? $max_dis_length : count($ret); $rand_keys = array_rand($ret, $rand_num); if (is_array($rand_keys)) { foreach ($rand_keys as $k) { $return_list[$wd][] = $ret[$k]; } } else { $return_list[$wd][] = $ret[0]; } } else { $return_list[$wd] = array(); } } } $result['letter'] = $letter_list; $result['words'] = $return_list; return $result; }
private function getStillFindDatas($diseaseName) { $queries[] = array('word' => $diseaseName, 'indexer' => 'index_9939_com_v2_keywords_all', 'offset' => 0, 'size' => 12, 'condition' => array(array('filter' => 'filter', 'args' => array('typeid', array(99))))); $all_word_ids = SearchHelper::batchSearch($queries); $arr_ids = array(); foreach ($all_word_ids as $k => $ret) { if (!empty($ret['matches'])) { foreach ($ret['matches'] as $kk => $kv) { $arr_ids[] = $kk; } } } $wd_obj = new KeyWords(); $result = $wd_obj->List_ByIds($arr_ids); return $result; }
/** * 疾病首页 下的 文章解读缓存部分 * @author gaoqing * @date 2016-04-15 * @param sting $cacheKey 缓存的唯一标识 * @param array $diseaseid 疾病id * @return array 文章解读数据集 */ public static function readArticleByDisease($cacheKey, $disease, $forceCache = false) { $cache = \Yii::$app->cache_data_file; $cacheFileName = $cacheKey . '_' . $disease['id']; $data = $cache->get($cacheFileName); if ($forceCache) { $data = false; } if (!isset($data) || empty($data)) { $conditions = array(array('word' => $disease['name'], 'indexer' => 'index_9939_com_jb_art', 'offset' => 0, 'size' => 4, 'condition' => array(array('filter' => 'filter', 'args' => array('tmp_type_id', array(2, 7))))), array('word' => $disease['name'], 'indexer' => 'index_9939_com_jb_art', 'offset' => 0, 'size' => 4, 'condition' => array(array('filter' => 'filter', 'args' => array('tmp_type_id', array(1, 3, 4))))), array('word' => $disease['name'], 'indexer' => 'index_9939_com_jb_art', 'offset' => 0, 'size' => 4, 'condition' => array(array('filter' => 'filter', 'args' => array('tmp_type_id', array(5))))), array('word' => $disease['name'], 'indexer' => 'index_9939_com_jb_art', 'offset' => 0, 'size' => 4, 'condition' => array(array('filter' => 'filter', 'args' => array('tmp_type_id', array(6, 8)))))); $diseaseArtids = SearchHelper::batchSearch($conditions); $result = array(); $keys = ['病因是什么', '症状有哪些', '怎么治疗', '如何护理']; foreach ($diseaseArtids as $key => $ret) { $indexer_name = $ret['indexer']; $sphinx_result = Search::parse_search_data($ret, $indexer_name); $ret_list = []; if (!empty($sphinx_result['list'])) { $ret_list = $sphinx_result['list']; } $result[$keys[$key]] = $ret_list; } if (!empty($result)) { $data = $result; $cache->set($cacheFileName, $result, self::DURATION); } } return $data; /* $cache = \Yii::$app->cache_data_file; $cacheFileName = $cacheKey . '_' . $disease['id']; $data = $cache->get($cacheFileName); if ($forceCache){ $data = false; } if (!isset($data) || empty($data)){ $article = new DArticle(); $allReads = []; $moduleMap = [ '病因是什么' => [2, 7], '症状有哪些' => [1, 3, 4], '怎么治疗' => [5], '如何护理' => [6, 8], ]; foreach ($moduleMap as $key => $types){ $preList = $article->getListByDiseaseid(['diseaseid' => $disease['id'], 'type' => $types], 0, 4); $allReads[$key] = $preList; } if (!empty($allReads)){ $data = $allReads; $cache->set($cacheFileName, $allReads); } } return $data; */ }
/** * 首页右侧热门关注 * sphinx调用疾病文章查询 * @return array latestFucus 对应的数据集合 */ public function latestFucus() { $cache = \Yii::$app->cache_file; $cache_key = 'frontend_seek_right_rmgz'; //疾病搜索页面_右侧_热门关注 $data = $cache->get($cache_key); if (!empty($data)) { return $data; } else { $queries = array(array('word' => '高血压', 'indexer' => 'index_9939_com_jb_art'), array('word' => '心脏病', 'indexer' => 'index_9939_com_jb_art'), array('word' => '包皮过长', 'indexer' => 'index_9939_com_jb_art'), array('word' => '乳腺增生', 'indexer' => 'index_9939_com_jb_art'), array('word' => '胃溃疡', 'indexer' => 'index_9939_com_jb_art'), array('word' => '宫颈癌', 'indexer' => 'index_9939_com_jb_art'), array('word' => '癫痫病', 'indexer' => 'index_9939_com_jb_art'), array('word' => '阳痿', 'indexer' => 'index_9939_com_jb_art'), array('word' => '哮喘', 'indexer' => 'index_9939_com_jb_art'), array('word' => '龋齿', 'indexer' => 'index_9939_com_jb_art')); $result = []; $ret = \librarys\helpers\utils\SearchHelper::batchSearch($queries); foreach ($ret as $kk => $ret) { $indexer_name = $ret['indexer']; $sphinx_result = Search::parse_search_data($ret, $indexer_name); $ret_list = $sphinx_result['list']; $kw = $queries[$kk]['word']; $result[$kw] = $ret_list; } $cache->set($cache_key, $result, 24 * 3600); return $result; } }
/** * 首页 疾病资讯 inc_mid_news文件里的数据缓存 * @param string $cacheKey * @param type $parms * @return */ public static function cacheIndexNewsBySphinx($cacheKey, $parms) { $newWords = $parms['newWords']; $art_obj = new \common\models\disease\Article(); $cache = \Yii::$app->cache_data_file; $key = $cacheKey; $data = $cache->get($key); if (!isset($data) || empty($data)) { //1、根据不同的词拼出sphinx批量查询的条件 $conditon = []; $n = 0; foreach ($newWords as $k => $v) { $w = $n; $conditon[$w] = ['word' => $k, 'indexer' => 'index_9939_com_jb_art']; $n++; } // print_r($conditon);exit; //2、根据sphinx批量查询得到记录 $sphinxRecords = SearchHelper::batchSearch($conditon); $result = array(); foreach ($sphinxRecords as $kk => $ret) { $indexer_name = $ret['indexer']; $sphinx_result = Search::parse_search_data($ret, $indexer_name); $ret_list = $sphinx_result['list']; $kw = $conditon[$kk]['word']; $result[$kw] = $ret_list; } // //7、设置缓存 // $cache->set($key, $result); return $result; } else { return $data; } }