Exemplo n.º 1
0
 /**
  * 
  * @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;
 }
Exemplo n.º 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);
 }
 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;
 }
Exemplo n.º 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);
 }