예제 #1
0
 public function actionSearch()
 {
     // flag to display results in home
     $flag = 2;
     $bool = false;
     $keyword = "";
     $result = array();
     // words to search for
     if (isset($_GET['keyword'])) {
         $keyword = $_GET['keyword'];
     }
     // array to contain the results of the search
     $results = array();
     $result2 = array();
     // there are words to search
     if ($keyword != null) {
         // operators for boolean search mode
         if (preg_match('/("|-)/', $keyword)) {
             $bool = true;
         }
         if ($bool == true) {
             // search FULLTEXT IN BOOLEAN MODE to allow for operations such as ' ""'  and ' - '
             $results = Job::model()->findAllBySql("SELECT * FROM job WHERE MATCH(type,title,description,comp_name) AGAINST ('%" . $keyword . "%' IN BOOLEAN MODE) AND active = '1';");
         }
         if ($bool == false) {
             // search FULLTEXT IN NATURAL LANGUAGE MODE
             $results = Job::model()->findAllBySql("SELECT * FROM job WHERE MATCH(type,title,description,comp_name) AGAINST ('%" . $keyword . "%' IN NATURAL LANGUAGE MODE) AND active = '1';");
             //print_r ($result);
         }
         // location will be set to "Miami, Florida"
         $loc = "Miami, Florida";
         // call indeed API to get jobs query by user
         $result = $this->indeed($keyword, $loc);
         if ($result['totalresults'] == 0) {
             $result = "";
         }
         $result2 = $this->careerBuilder($keyword, $loc);
         if ($result2[0] == 0) {
             $result2 = "";
         }
     }
     // get user
     if (isset($_GET['user'])) {
         $username = $_GET['user'];
     } else {
         $username = Yii::app()->user->name;
     }
     // pass user
     $user = User::model()->find("username=:username", array(':username' => $username));
     // pass skills
     $skills = Skillset::getNames();
     // pass companies
     $companies = CompanyInfo::getNames();
     //print_r($result); return;
     // render search results, user, skills, companies and flag to job/home
     $this->render('home', array('result' => $result, 'cbresults' => $result2, 'jobs' => $results, 'user' => $user, 'companies' => $companies, 'skills' => $skills, 'flag' => $flag));
 }
예제 #2
0
 public function actionSearch()
 {
     $flag = 1;
     $keyword = $_POST['keyword'];
     // Get words to search
     $pieces = trim($keyword);
     $pieces = explode(" ", $pieces);
     // split words to search
     $count = sizeof($pieces);
     // get number of word to search
     $query = '';
     for ($i = 0; $i < $count; $i++) {
         if ($i == $count - 1) {
             $query = $query . 'name like \'%' . $pieces[$i] . '%\'';
         } else {
             $query = $query . 'name like \'%' . $pieces[$i] . '%\' OR ';
         }
     }
     $criteria = new CDbCriteria();
     $criteria->condition = $query;
     $results = array();
     if ($keyword != null) {
         $skillsArray = Skillset::model()->findAll($criteria);
         foreach ($skillsArray as $sk) {
             if ($sk != null) {
                 $jobIds = JobSkillMap::model()->findAllByAttributes(array('skillid' => $sk->id));
                 // get all jobs with that skill
                 if ($jobIds != null) {
                     foreach ($jobIds as $ji) {
                         if ($ji != null) {
                             $jobid = $ji->jobid;
                             $duplicate = 0;
                             if (sizeof($results) > 0) {
                                 foreach ($results as $t) {
                                     if ($t != null) {
                                         if (strcmp($t->id, $jobid) == 0) {
                                             $duplicate = 1;
                                         }
                                     }
                                 }
                             }
                             if ($duplicate == 0) {
                                 $results[] = Job::model()->findByAttributes(array('id' => $jobid, 'active' => '1'));
                                 // search for skill only
                             }
                         }
                     }
                 }
             }
         }
         $compsArray = CompanyInfo::model()->findAll($criteria);
         foreach ($compsArray as $co) {
             if ($co != null) {
                 $comp_posts = Job::model()->findAllByAttributes(array('FK_poster' => $co->FK_userid));
                 if ($comp_posts != null) {
                     foreach ($comp_posts as $cp) {
                         $duplicate = 0;
                         if (sizeof($results) > 1) {
                             if ($cp != null) {
                                 foreach ($results as $t) {
                                     if ($t != null) {
                                         if ($t->id == $cp->id) {
                                             $duplicate = 1;
                                         }
                                     }
                                 }
                             }
                         }
                         if ($duplicate == 0) {
                             $results[] = Job::model()->findByAttributes(array('id' => $cp->id, 'active' => '1'));
                         }
                     }
                 }
             }
         }
     }
     if (isset($_GET['user'])) {
         $username = $_GET['user'];
     } else {
         $username = Yii::app()->user->name;
     }
     $user = User::model()->find("username=:username", array(':username' => $username));
     // pass user
     $skills = Skillset::getNames();
     // pass skills
     $companies = CompanyInfo::getNames();
     // pass companies
     $this->render('home', array('flag' => $flag, 'results' => $results, 'user' => $user, 'companies' => $companies, 'skills' => $skills));
     //$this->render('studentSearchResults',array('results'=>$results,'user'=>$user,'companies'=>$companies,'skills'=>$skills,));
 }