/**
  * 
  * @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;
 }
Example #2
0
 /**
  * 
  * @param type $sphinx_data
  * @return type
  */
 public static function search_words_all_data($sphinx_data)
 {
     $total = 0;
     $ret_list = array();
     if (!empty($sphinx_data['matches'])) {
         $arr_ids = array();
         $wd_obj = new KeyWords();
         foreach ($sphinx_data['matches'] as $k => $v) {
             $arr_ids[] = $k;
         }
         $ret_list = $wd_obj->List_ByIds($arr_ids);
         $total = $sphinx_data['total'];
     }
     $explain_words = $sphinx_data['explain_words'];
     return array('list' => $ret_list, 'total' => $total, 'explain_words' => $explain_words);
 }
Example #3
0
 /**
  * 生成 404 静态页面
  * @author gaoqing
  * @date 2016-04-20
  * @param string $cacheKey 缓存的唯一标识
  * @return boolean$generateFlag是否生成成功
  */
 public static function cache404Page($cacheKey, $param = [], $forceCache = false)
 {
     $generateFlag = false;
     $frontend = \Yii::getAlias('@frontend');
     $page404FileName = $frontend . '/web/404.shtml';
     if (!file_exists($page404FileName)) {
         $forceCache = true;
     }
     if ($forceCache) {
         $view = "404";
         //获取最新的资讯文章
         $article = new Article();
         $where = ' status=20';
         $order = ' articleid DESC';
         $lastestNews = $article->List_Articles($where, $order, 5, 0);
         //获取 疾病健康 文章
         $darticle = new \common\models\disease\Article();
         $lastestJibingArticle = $darticle->getLatestArticle(5, 0);
         //精彩问答
         $ask = new Ask();
         $where1 = ' 1';
         $order1 = ' id DESC';
         $lastestAsk = $ask->getList($where1, $order1, 5, 0);
         //字母部分
         $letters = range('A', 'Z');
         $condition = array('typeid' => array(0, 2, 3, 4, 5, 6, 7, 8, 9));
         $rand_words = KeyWords::getCacheRandWords(100, $condition);
         //热门疾病、热门部位
         $commonDisDep = CacheHelper::getCache('frontend_article_detail_rmksbw_404', []);
         $params = ['lastestNews' => $lastestNews, 'lastestJibingArticle' => $lastestJibingArticle, 'lastestAsk' => $lastestAsk, 'letters' => $letters, 'rand_words' => $rand_words, 'commonDisDep' => $commonDisDep, 'searchurl' => 'http://www.9939.com/zhuanti/'];
         $controller = new BaseController('base404', null);
         $controller->id = "base404";
         $page404FilePath = $frontend . '/views/site';
         $controller->viewPath = $page404FilePath;
         $page404 = $controller->renderPartial($view, $params);
         if (isset($page404) && !empty($page404)) {
             if (file_put_contents($page404FileName, $page404)) {
                 $generateFlag = true;
             }
         }
     }
     return $generateFlag;
 }
Example #4
0
 public static function search_batch_words_all($wd, $offset, $size, array $condition = array())
 {
     $total = 0;
     $ret_list = array();
     $explain_words = array($wd);
     if (!empty($wd)) {
         $search_result = SearchHelper::Search_batch($wd, 'index_9939_com_v2_keywords_all', $offset, $size, $condition);
         if (isset($search_result) && !empty($search_result)) {
             $arr_ids = array();
             $wd_obj = new KeyWords();
             foreach ($search_result as $search) {
                 if (isset($search['matches']) && !empty($search['matches'])) {
                     $arr_ids = array_merge($arr_ids, array_keys($search['matches']));
                 }
             }
             $ret_list = $wd_obj->List_ByIds($arr_ids);
             //$total = $search_result['total'];
         }
         $explain_words = $search_result['explain_words'];
     }
     return array('list' => $ret_list, 'explain_words' => $explain_words);
 }
 private function rand_words()
 {
     $letter_list = 'abcdefghijklmnopqrstuvwxyz';
     $len = strlen($letter_list);
     $return_list = array();
     $max_kw_length = 100;
     $max_dis_length = 28;
     $filter_array = $this->getFilterArray();
     $cache_rand_words = KeyWords::getCacheRandWords($max_kw_length, $filter_array);
     for ($i = 0; $i < $len; $i++) {
         $wd = strtoupper($letter_list[$i]);
         if (array_key_exists($wd, $cache_rand_words)) {
             $ret = $cache_rand_words[$wd];
             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();
             }
         } else {
             $return_list[$wd] = array();
         }
     }
     return $return_list;
 }
Example #6
0
 private function getCreateData($start_article_id = 0, $max_article_id = 0, $max_diff = 10000, &$art_list = array())
 {
     $total_record = count($art_list);
     if ($total_record <= $max_diff && $start_article_id <= $max_article_id) {
         $kw_obj = new KeyWords();
         $end_article_id = $start_article_id + $max_diff;
         //            $where = "id > '{$start_article_id}' and id < '{$end_article_id}' and typeid = 99 ";
         $where = "id > '{$start_article_id}' and typeid = 99 ";
         $offset = 0;
         $count = $max_diff - $total_record;
         $tmp_art_list = $kw_obj->List_All($where, 'id asc', $count, $offset);
         if ($count > 0) {
             $tmp_art_list = $kw_obj->List_All($where, 'id asc', $count, $offset);
             if ($tmp_art_list) {
                 $art_list = array_merge($art_list, $tmp_art_list);
                 $total_record = count($art_list);
                 $start_article_id = $art_list[$total_record - 1]['id'];
             } else {
                 $start_article_id = $end_article_id;
                 $total_record = count($art_list);
             }
             $this->getCreateData($start_article_id, $max_article_id, $max_diff, $art_list);
         }
     }
 }
#!/usr/bin/php
#/usr/bin/php /data/www/develop/code/trunk/admin-9939-com/console/shell/createcacherandwords.php >/dev/null 2>&1

<?php 
$app_path = dirname(__DIR__);
require $app_path . '/config/init.php';
\common\models\KeyWords::createCacheRandWords(array(array('filter' => 'filter', 'args' => array('typeid', array(99)))));
\common\models\KeyWords::createCacheRandWords(array(array('filter' => 'filter', 'args' => array('typeid', array(0, 2, 3, 4, 5, 6, 7, 8, 9)))));