コード例 #1
0
ファイル: SearchController.php プロジェクト: skybird/phalcon
 public function indexAction()
 {
     $keyword = trim($this->request->getQuery("q"));
     if (!$keyword) {
         $tag = new Tag();
         $tags = $tag->getPopularTags(30);
         $this->view->setVar('tags', $tags);
         return;
     }
     $client = new \Elasticsearch\Client(array('hosts' => $this->getDI()->getConfig()->EvaSearch->elasticsearch->servers->toArray()));
     $searchParams['index'] = 'wallstreetcn';
     $type = $this->request->getQuery('type');
     $type = in_array($type, array('article', 'wiki', 'livenews')) ? $type : 'article';
     $searchParams['type'] = $type;
     $searchParams['size'] = 15;
     $page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
     $page = $page > 0 ? $page : 1;
     $searchParams['from'] = ($page - 1) * $searchParams['size'];
     $searchParams['body']['query']['multi_match'] = array('query' => $keyword, "fields" => array("title", "content"), "tie_breaker" => 0.3);
     $searchParams['body']['highlight'] = array("fields" => array("title" => array("type" => "plain"), "content" => array("fragment_size" => 50, "number_of_fragments" => 3, "type" => "plain")));
     $searchParams['body']['filter'] = array("bool" => array("should" => array("term" => array("status" => "published"))));
     $searchParams['body']['sort'] = array('createdAt' => array('order' => 'desc'), '_score' => array('order' => 'desc'));
     $ret = $client->search($searchParams);
     $this->view->setVar('hits', $ret['hits']);
     $pager = new PurePaginator($searchParams['size'], $ret['hits']['total'], $ret['hits']['hits']);
     $this->view->setVar('pager', $pager);
     $this->view->setVar('keyword', $keyword);
 }
コード例 #2
0
ファイル: NewsController.php プロジェクト: skybird/phalcon
 public function indexAction()
 {
     $limit = $this->request->getQuery('limit', 'int', 25);
     $limit = $limit > 100 ?: $limit;
     $limit = $limit < 10 ?: $limit;
     $order = $this->request->getQuery('order', 'string', '-created_at');
     $query = array('q' => $this->request->getQuery('q', 'string'), 'status' => 'published', 'tid' => $this->request->getQuery('tid', 'int'), 'uid' => $this->request->getQuery('uid', 'int'), 'cid' => $this->request->getQuery('cid', 'int'), 'username' => $this->request->getQuery('username', 'string'), 'order' => $order, 'limit' => $limit, 'page' => $this->request->getQuery('page', 'int', 1));
     if ($query['cid']) {
         $this->view->setVar('category', Category::findFirst($query['cid']));
     }
     if ($query['uid']) {
         $this->view->setVar('author', UserManager::findFirst($query['uid']));
     }
     if ($query['tid']) {
         $this->view->setVar('tag', Tag::findFirst($query['tid']));
     }
     $post = new Post();
     $posts = $post->findPosts($query);
     $paginator = new \Eva\EvaEngine\Paginator(array("builder" => $posts, "limit" => $limit, "page" => $query['page']));
     $paginator->setQuery($query);
     $pager = $paginator->getPaginate();
     $this->view->setVar('pager', $pager);
     $this->view->setVar('query', $query);
     $tag = new Tag();
     $tags = $tag->getPopularTags(6);
     $this->view->setVar('tags', $tags);
 }
コード例 #3
0
ファイル: SearchController.php プロジェクト: skybird/phalcon
 public function indexAction()
 {
     $keyword = trim($this->request->getQuery("q"));
     $postSearcher = new PostSearcher();
     $pager = $postSearcher->searchPosts(array('q' => $keyword, 'highlight' => true, 'order' => '-created_at', 'status' => 'published'));
     $this->view->setVar('pager', $pager);
     $this->view->setVar('keyword', $keyword);
     $tag = new Tag();
     $tags = $tag->getPopularTags(6);
     $this->view->setVar('tags', $tags);
 }