/** * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface|View */ public function indexAction() { $this->tag->setTitle('Search Results'); $q = $this->request->getQuery('q', 'string'); $indexer = new Indexer(); $posts = $indexer->search(['title' => $q, 'content' => $q], 50, true); if (!count($posts)) { $posts = $indexer->search(['title' => $q], 50, true); if (!count($posts)) { $this->flashSession->notice('There are no search results'); return $this->response->redirect(); } } $this->view->setVars(['tab' => null, 'posts' => $posts, 'canonical' => '', 'totalPages' => 1, 'currentPage' => null]); return $this->view->pick('post'); }
/** * Finds related posts */ public function showRelatedAction() { if ($this->request->isAjax()) { $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $post = Posts::findFirstById($this->request->getPost('id')); if ($post) { $indexer = new Indexer(); $posts = $indexer->search(['title' => $post->getTitle(), 'content' => $post->getContent()], 5, true); if (count($posts) == 0) { $posts = $indexer->search(['title' => $post->title], 5, true); } $this->view->object = $posts; } else { $this->view->object = array(); } return 1; } }
/** * Finds related posts */ public function showRelatedAction() { $this->view->disable(); if ($this->request->isAjax()) { #$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $post = Posts::findFirstById($this->request->getPost('id')); if ($post) { $indexer = new Indexer(); $posts = $indexer->search(['title' => $post->getTitle(), 'content' => $post->getContent()], 5, true); if (count($posts) == 0) { $posts = $indexer->search(['title' => $post->title], 5, true); } if (count($posts) > 0) { $params = ['posts' => $posts]; echo $this->view->getRender('partials', 'list-posts', $params, function ($view) { $view->setRenderLevel(View::LEVEL_ACTION_VIEW); }); } } } }
/** * Get post related via elastic * * @param object $post * @return object */ public static function postRelated($post) { $indexer = new Indexer(); $posts = $indexer->search(['title' => $post->title, 'content' => $post->content], 5, true); if (count($posts) == 0) { $posts = $indexer->search(['title' => $post->title], 5, true); } return $posts; }