public function actionIndex() { $keyword = trim(yii::app()->request->getParam('q', '')); $keyword = strip_tags($keyword); $search_type = trim(yii::app()->request->getParam('type', '')); $page = intval(yii::app()->request->getParam('page', 1)); $is_search = Yii::app()->request->getParam('is_search', 1); $paging = array('page' => $page, 'recordsPerPage' => !$search_type ? Yii::app()->params['numberPerPage'] : Yii::app()->params['pageSize']); $limit = 5; $searchType = !$search_type ? $this->type_infos : array($search_type => ''); $total_results = array(); foreach ($searchType as $type => $info) { switch ($type) { case 'song': $response = SearchHelper::getInstance()->search($keyword, 'song', $limit, $page - 1); $results = $this->copyAndCast($response->docs, array('name' => 'name', 'artist_name' => 'artist_name')); $results = $this->getStatistic($results, $type); $countSong = $response->numFound; $pages = new CPagination($countSong); $pageSize = Yii::app()->params['pageSize']; $pages->params = array('q' => $keyword, 'type' => $type); $pages->setPageSize($pageSize); $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'pages' => $pages); break; case 'clip': $response = SearchHelper::getInstance()->search($keyword, 'video', $limit, $page - 1); $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name')); $results = $this->getStatistic($results, $type); $countClip = $response->numFound; $pages = new CPagination($countClip); $pageSize = Yii::app()->params['pageSize']; $pages->params = array('q' => $keyword, 'type' => $type); $pages->setPageSize($pageSize); $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'pages' => $pages); break; case 'album': $response = SearchHelper::getInstance()->search($keyword, 'album', $limit, $page - 1); $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name')); $results = $this->getStatistic($results, $type); $countAlbum = $response->numFound; $pages = new CPagination($countAlbum); $pageSize = Yii::app()->params['pageSize']; $pages->params = array('q' => $keyword, 'type' => $type); $pages->setPageSize($pageSize); $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'pages' => $pages); break; case 'artist': $response = SearchHelper::getInstance()->search($keyword, 'artist', $limit, $page - 1); $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name')); $results = $this->getStatistic($results, $type, 'song_count'); $countArtist = $response->numFound; $pages = new CPagination($countArtist); $pageSize = Yii::app()->params['pageSize']; $pages->params = array('q' => $keyword, 'type' => $type); $pages->setPageSize($pageSize); $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'pages' => $pages); $listArtist = ArtistModel::updateResultFromSearch($this->copyAndCast($response->docs, array())); $artistSeach = trim($listArtist[0]['name']); if ($artistSeach == $keyword || Common::makeFriendlyUrl($artistSeach) == Common::makeFriendlyUrl($keyword)) { $urlKey = Common::makeFriendlyUrl(trim($listArtist[0]['name'])); $link = Yii::app()->createUrl("artist/view", array("id" => $listArtist[0]['id'], "title" => $urlKey)); $this->redirect($link); } break; case 'videoplaylist': $response = SearchHelper::getInstance()->search($keyword, 'videoplaylist', $limit, $page - 1); $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name')); $results = $this->getStatistic($results, $type); $countVideoPlaylist = $response->numFound; $pages = new CPagination($countVideoPlaylist); $pageSize = Yii::app()->params['pageSize']; $pages->params = array('q' => $keyword, 'type' => $type); $pages->setPageSize($pageSize); $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'pages' => $pages); break; } } if ($is_search == '0') { $this->render('list_rbt', array('keyword' => $keyword, 'search_type' => $search_type, 'total_results' => $total_results, 'type_infos' => $this->type_infos)); } // echo '<pre>';print_r($total_results); $this->render('result', array('keyword' => $keyword, 'search_type' => $search_type, 'total_results' => $total_results, 'type_infos' => $this->type_infos)); }