Esempio n. 1
0
 public static function getFullPy($word)
 {
     $RET = '';
     if ($word) {
         $word = SearchUtil::EscapeKeyword($word);
         // 分词
         $url = sprintf('http://360xun.sinaapp.com/api/segment?words=%s', urlencode($word));
         $segWord = httpClient::curlRequset($url);
         // 中文单字
         $singleWordArr = self::SplitSingleChinese($word);
         $singleWord = implode(' ', $singleWordArr);
         // 中文拼音前缀
         $preWordArr = self::SplitChinese($word);
         $preWord = implode(' ', $preWordArr);
         $pySegWord = Pinyin::str2py($segWord);
         $pySingleWord = Pinyin::str2py($singleWord);
         $pyPreWord = Pinyin::str2py($preWord);
         $segArr = explode(' ', $segWord);
         $engArr = array();
         if ($segArr) {
             foreach ($segArr as $s) {
                 if (preg_match('/^[a-zA-Z]+$/is', $s)) {
                     if ($engs = self::SplitEnglish($s, 3)) {
                         $engArr = array_merge($engArr, $engs);
                     }
                 }
             }
         }
         $RET = $pySegWord . ' ' . $pySingleWord . ' ' . $pyPreWord;
         if ($engArr) {
             $RET = implode(' ', $engArr) . ' ' . $RET;
         }
         $RET_ARR = array_unique(explode(' ', $RET));
         $RET = implode(' ', $RET_ARR);
         $RET = trim($RET);
     }
     return $RET;
 }
Esempio n. 2
0
 public function search($keyword, $page = 1, $pageSize = 10, &$hasMore = false, &$cacheHit = false)
 {
     $RET = [];
     $searchRs = [];
     /*
             if($soft_type == self::APPSTORE) {
        $cache = Factory::Redis(ClusterRedis::CLUSTER_APP);
        list($keywordCacheKey,$expire) = $cache->GetStrategy()->GetAppSearchKey($keyword);
             } elseif($soft_type == self::GAME_CENTER) {
        $cache = Factory::Redis(ClusterRedis::CLUSTER_GAME_APP);
        list($keywordCacheKey,$expire) = $cache->GetStrategy()->GetAppSearchKey($keyword);
             }
     */
     /** get Cache 
         if(AppLogic::IsUseCache())
         {
             if($keywordCacheKey && ($res = $cache->get($keywordCacheKey)) && ($searchRs = Util::JsonDec($res, TRUE)))
             {
                 $cacheHit = TRUE;
             }
         }*/
     if (!isset($searchRs) || empty($searchRs)) {
         // 判断是否是包名
         //if( !$this->isPackage($keyword) ) {
         // 繁体转简体
         //$keyword = ChineseConvert::t2s($keyword);
         //$categoryId = CategoryLogic::GetCategoryMap($keyword);
         // 分词
         $url = sprintf('http://360xun.sinaapp.com/api/segment?words=%s', urlencode($keyword));
         $segWord = httpClient::curlRequset($url);
         $pySegWord = Pinyin::str2py($segWord);
         /*
                         // 如果分词结果不是字符串
                         if(!is_string($segWord)) {
            return false;
                         }
         */
         // 整词列表
         /*
                         if( $this->WholeWords($keyword) ) {
            $segWord .= '|('.$keyword.')';
                         }
         */
         // 分词结果转拼音
         //$pyWord = py_class::str2py($segWord);
         //Log::Single()->Info('Search Word', array('key'=>$keyword, 'seg'=>$segWord, 'py'=>$pyWord, 'p'=>$page, 'size'=>$pageSize));
         //$pyWord = $this->filterKeyword($pyWord);
         //} else {
         /*
                         $segWord = '';
                         $pyWord = '';
                         $package = $keyword;
                         Log::Single()->Info('Search package', array('key'=>$keyword, 'p'=>$page, 'size'=>$pageSize));
         */
         //}
         $this->search->setFilterRange('status', 1, 1);
         $this->search->setMatchMode(SPH_MATCH_EXTENDED2);
         $this->search->setSortMode(SPH_SORT_EXTENDED, '@relevance DESC, update_time DESC, rating DESC');
         $this->search->setFieldWeights($this->GetSearchWeightMap());
         $this->search->setMaxQueryTime(3000);
         $this->search->setRankingMode(SPH_RANK_SPH04);
         //$this->search->setRankingMode(SPH_RANK_EXPR, 'sum((exact_hit*5+(min_hit_pos==1)*2+lcs)*user_weight)*1000+bm25');
         $this->search->setLimits(0, 100, self::DEFAULT_SEARCH_TOTAL, self::DEFAULT_SEARCH_TOTAL);
         $this->search->setArrayResult(TRUE);
         $indexs = implode(',', $this->GetSearchIndex());
         $filterWordArr = $this->GetSearchFilterWord();
         $filterDeveloper = 0;
         foreach ($filterWordArr as $word) {
             if (strpos($keyword, $word) !== FALSE) {
                 $filterDeveloper = 1;
                 break;
             }
         }
         $seg_keyword = $segWord;
         $seg_keyword = array_filter(explode(' ', $seg_keyword));
         $seg_keyword = '(' . implode(')|(', $seg_keyword) . ')';
         //var_dump($seg_keyword);die;
         // addQuerys
         $this->search->addQuery("@title {$seg_keyword}", $indexs);
         $this->search->addQuery("@original_title {$seg_keyword}", $indexs);
         $this->search->addQuery("@aka {$seg_keyword}", $indexs);
         $this->search->addQuery("@directors {$seg_keyword}", $indexs);
         $this->search->addQuery("@casts {$seg_keyword}", $indexs);
         $this->search->addQuery("@year {$seg_keyword}", $indexs);
         $this->search->addQuery("@country {$seg_keyword}", $indexs);
         if ($pySegWord) {
             $py_keyword = $pySegWord;
             $py_keyword = array_filter(explode(' ', $py_keyword));
             $py_keyword = '(' . implode(')|(', $py_keyword) . ')';
             //$py_keyword = count($py_keyword)=1 ? '('.implode(')|(', $py_keyword).')' : $py_keyword;
             $this->search->addQuery("@py_title {$py_keyword}", $indexs);
             $this->search->addQuery("@py_original_title {$py_keyword}", $indexs);
             /*
                             $pyWordArr = explode('|', $pyWord);
                             foreach($pyWordArr as $pyName) {
                                 $this->search->addQuery("@py_name {$pyName}", $indexs);
                             }
                             $this->search->addQuery("@py_cname {$pyWord}", $indexs);
             */
         }
         $res = $this->search->runQueries();
         if (is_array($res)) {
             $error = '';
             $warning = '';
             $searchRs = array();
             foreach ($res as $k => $v) {
                 if (isset($v['error']) && $v['error']) {
                     $error .= $k . ':' . $v['error'] . ' & ';
                 }
                 if (isset($v['warning']) && $v['warning']) {
                     $warning .= $k . ':' . $v['warning'] . ' & ';
                 }
                 // matches
                 if (isset($v['matches']) && $v['matches']) {
                     foreach ($v['matches'] as $data) {
                         if (!array_key_exists($data['id'], $searchRs)) {
                             $searchRs[$data['id']] = $data['weight'];
                         } else {
                             $searchRs[$data['id']] += $data['weight'];
                         }
                     }
                 }
             }
             arsort($searchRs);
             /** 写Cache 
                 if($searchRs && $keywordCacheKey)
                 {
                     $cache->multi(Redis::MULTI);
                     $cache->set($keywordCacheKey, Util::JsonEnc($searchRs));
                     $expire && $cache->expire($keywordCacheKey, $expire);
                     $cache->exec();
                 }*/
             // log error
             if (!empty($error)) {
                 //Log::Single()->Error("Sphinx error", array('error'=>$error, 'keyword'=>$keyword, 'segWord'=>$segWord, 'py'=>$pyWord));
             }
             // log warning
             if (!empty($warning)) {
                 //Log::Single()->Warn("Sphinx warning", array('warning'=>$warning));
             }
         }
     }
     if (isset($searchRs) && $searchRs) {
         $page = $page <= 0 ? 1 : $page;
         $pageSize = $pageSize <= 0 ? 10 : $pageSize;
         $offset = ($page - 1) * $pageSize;
         $sliceSearchRs = array_slice($searchRs, $offset, $pageSize + 1, TRUE);
         $count = count($sliceSearchRs);
         $hasMore = $count >= $pageSize + 1 ? TRUE : FALSE;
         $idx = 0;
         foreach ($sliceSearchRs as $appId => $weight) {
             $RET[$appId] = $weight;
             $idx++;
             if ($idx >= $pageSize) {
                 break;
             }
         }
     }
     return $RET;
 }
Esempio n. 3
0
 /**
  * 播放iframe test
  */
 public function actionPlayIframeTest($basic_id, $sid = 0)
 {
     $device = CommonTool::getDevice();
     var_dump($device);
     die;
     /*
             //$url = 'http://www.511yc.com/js/player.php?vid=9593&pid=0&nextid=0';
             $url = 'http://m.wxdy.cc/?m=vod-play-id-1209-src-1-num-1.html';
             $rs = Sniff::wxdy($url);
     echo $rs;die;
     */
     die;
     //$url = 'http://www.511yc.com/js/player.php?vid=9572&pid=0&nextid=0';
     $url = 'http://www.ttdyy.tv/js/player.php?vid=4072&pid=1&nextid=0';
     $header = ["Referer:http://www.ttdyy.tv/player/4023_0.html", 'Cookie:ishistory=0; HISTORY={video:[{"name":"\\u5341\\u4E8C\\u516C\\u6C11","link":"http://ttdyy.tv/show/3670.html ","pic":"http://r2.ykimg.com/050E000056024FDD67BC3C06C8088330"},{"name":"\\u89E3\\u6551\\u543E\\u5148\\u751F","link":"http://ttdyy.tv/show/3632.html ","pic":"http://r3.ykimg.com/050E000055FA1ED667BC3C1A9C04D19D"},{"name":"\\u590F\\u6D1B\\u7279\\u70E6\\u607C","link":"http://ttdyy.tv/show/3682.html ","pic":"http://r4.ykimg.com/050E000055E95EB267BC3C6D10020BCB"},{"name":"\\u6697\\u6740","link":"http://ttdyy.tv/show/1643.html ","pic":"http://r1.ykimg.com/050E000055B0ADC767BC3C43EC045655"},{"name":"\\u6E2F\\u56E7","link":"http://ttdyy.tv/show/1519.html ","pic":"http://r1.ykimg.com/050E000055A7630167BC3C728D04EB00"}]}; CNZZDATA1255309975=1396216497-1444183242-%7C1444539975; CNZZDATA1254170186=190506882-1444181571-%7C1444540105', "User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"];
     $html = httpClient::curlRequset($url, $header);
     var_dump($html);
     die;
     die;
     $device = CommonTool::getDevice();
     $source = models\MvSource::find()->where(['id' => $sid, 'basic_id' => $basic_id, 'status' => models\MvSource::STATUS_SHOW])->orderBy('sort desc, update_time DESC')->asArray()->one();
     if (isset($source['type']) && $source['type'] == 3) {
         $source['play_url'] = Sniff::ttyy($source['play_url']);
         //var_dump($rs);die;
     } elseif (isset($source['type']) && $source['type'] == 4) {
         $pcs = new BaiduPCS();
         $source['play_url'] = $pcs->createUrl($source['play_url']);
     }
     return $this->renderPartial('movie_play_iframe_test', ['source' => $source, 'device' => $device['device'], 'browser' => $device['browser']]);
 }