コード例 #1
0
 private function doSearch($keywords)
 {
     $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
     //$protocol = "http";
     $domainName = $_SERVER['HTTP_HOST'];
     require_once 'ServiceUtil.php';
     require_once 'Config.php';
     $this->load->helper('url');
     $myConfig = new Config();
     $myConfig->loadJsonConfig($data);
     $util = new ServiceUtil();
     $keywords = str_replace(" ", "%20", $keywords);
     /*$sources = $this->loadSourcesConfig($data);
       if($sources != null)
       {
           $data['ks_sources'] = $sources;
           
       }*/
     //Loading categories configurations
     /*$categories = $this->loadCategoriesConfig($data);
       if($categories != null)
       {
           $data['categories'] = $categories;
       }*/
     $termResult = $util->getTerm($keywords);
     //var_dump($termResult);
     $termSize = 0;
     if (!is_null($termResult)) {
         $termSize = count($termResult);
     }
     //echo "------Term size:".$termSize."<br/>\n";
     if ($termSize == 1) {
         //echo "------Curie:".$termResult[0]->curie."<br/>\n";
         if (isset($termResult[0]->curie)) {
             //echo "<br/><center>Redirecting to ".$termResult[0]->curie." ...</center>";
             //redirect($protocol."://".$domainName."/".Config::$localContextName."/index.php/pages/view/".$termResult[0]->curie, 'refresh');
             redirect($protocol . $domainName . "/" . Config::$localContextName . "/index.php/pages/view/" . $termResult[0]->curie, 'location', 301);
         }
         return;
     }
     $searchResult = $util->searchTerm($keywords);
     $data['keywords'] = $keywords;
     $data['termResult'] = $termResult;
     if (!is_null($termResult)) {
         $searchResult = array_merge($termResult, $searchResult);
         $unique = array();
         $uniqueArray = array();
         foreach ($searchResult as $row) {
             if (isset($unique[$row->curie])) {
                 continue;
             } else {
                 $unique[$row->curie] = $row->curie;
                 array_push($uniqueArray, $row);
             }
         }
         $searchResult = $uniqueArray;
     }
     $data['searchResult'] = $searchResult;
     $data['page_title'] = "Search";
     $data['enable_config'] = false;
     $data['disableTopSearchBar'] = true;
     //var_dump($termResult);
     $this->load->view('templates/header2', $data);
     //$this->load->view('pages/'.$page, $data);
     $this->load->view('pages/search_result', $data);
     $this->load->view('templates/footer2', $data);
 }