Пример #1
0
	public function search(){
		$view     = $this->getView();
		$request  = $this->getPageRequest();

		if(!$request->getParameter('q')){
			// Simply redirect to the sitemap if no query was provided.
			\Core\redirect('/page/sitemap');
		}

		$search = new \Core\Search\SearchResults();
		$search->query = $request->getParameter('q');
		$results = PageModel::Search($request->getParameter('q'), ['indexable = 1']);

		$isadmin = \Core\user()->checkAccess('g:admin');

		foreach($results as $r){
			/** @var Core\Search\ModelResult $r */

			/** @var PageModel $model */
			$model = $r->_model;

			if(!$model->isPublished() && !$isadmin){
				// The page is not published and the user is not an admin, skip!
				continue;
			}

			// Skip the sitemap page iteself, as that will probably contain most of the keywords.
			if($model->get('baseurl') == '/page/sitemap'){
				continue;
			}

			if(!\Core\user()->checkAccess($model->get('access'))){
				// User does not have access to this page!
				continue;
			}

			if($r->relevancy < 10){
				// Not a good enough of a match.
				continue;
			}

			// Otherwise.
			$search->addResult($r);
		}

		$search->sortResults();

		HookHandler::DispatchHook('/core/page/search/results', $search);

		$view->title = 'Site Search';
		$view->assign('query', $request->getParameter('q'));
		$view->assign('results', $search);
	}