Пример #1
0
 public function searchAction()
 {
     if ($_GET['type'] == 'name') {
         return $this->redirect('/name/' . urlencode($_GET['q']));
     }
     if ($_GET['type'] == 'fund') {
         return $this->redirect('/fund/' . urlencode($_GET['q']));
     }
     if (preg_match('#\\d{8}#', $_GET['q'])) {
         return $this->redirect('/id/' . $_GET['q']);
     }
     $page = intval($_GET['page']) ?: 1;
     if (preg_match('#^address:(.*)$#', $_GET['q'], $matches)) {
         $ret = SearchLib::searchCompaniesByAddress($matches[1], $page);
     } else {
         $ret = SearchLib::searchCompaniesByName($_GET['q'], $page);
     }
     if ($ret->hits->total == 1) {
         return $this->redirect('/id/' . urlencode($ret->hits->hits[0]->_id));
     }
     $this->view->page = $page;
     $this->view->max_page = ceil($ret->hits->total / 10);
     $this->view->search_word = $_GET['q'];
     $this->view->search_result = $ret;
 }