00001 <?php
00002
00003
00004
00005
00006
00007
00008 class SearchIndexBaseController extends ControllerBase {
00009
00010
00011
00012
00013 public function get_routes() {
00014 $ret = array(
00015 'view' => new ExactMatchRoute('search/', $this, 'searchindex_search', new NoCacheCacheManager()),
00016 );
00017 return $ret;
00018 }
00019
00020
00021
00022
00023
00024
00025 public function action_searchindex_search($page_data) {
00026 $page_data->head->robots_index = ROBOTS_NOINDEX_FOLLOW;
00027 $page_data->breadcrumb = array(tr('Search', 'searchindex'));
00028 $view = ViewFactory::create_view(IViewFactory::CONTENT, 'searchindex/search', $page_data);
00029 $terms = trim($this->get_terms($page_data));
00030 if ($terms !== '') {
00031 if (!String::check_encoding($terms)) {
00032
00033
00034 if (String::check_encoding($terms, 'ISO-8859-1')) {
00035 $newterms = String::convert($terms, 'ISO-8859-1');
00036 }
00037 else {
00038 $newterms = String::convert($terms);
00039 }
00040 if ($newterms != $terms) {
00041 Url::current()->replace_query_parameter('q', $newterms)->redirect();
00042 }
00043 }
00044
00045 $page_data->head->title = tr('Search »%terms«', 'searchindex', array('%terms' => $terms));
00046 $page_data->head->description = tr('Search results for query »%terms«.', 'searchindex', array('%terms' => $terms));
00047
00048 $search = SearchIndexRepository::get_index_implementation();
00049 $search->set_search($terms);
00050
00051 Load::tools('pager', 'sorter');
00052 $pager = new Pager($page_data, $search);
00053 $pager->apply($search);
00054 $pager->prepare_view($view);
00055
00056 $sorter = new Sorter($page_data, $search);
00057 $sorter->apply($search);
00058 $sorter->prepare_view($view);
00059
00060 $view->assign('result', $search->execute());
00061 } else {
00062 $page_data->head->title = tr('Search', 'searchindex');
00063 }
00064 $view->assign('terms', $terms);
00065 $view->render();
00066 }
00067
00068
00069
00070
00071 protected function get_terms(PageData $page_data) {
00072 $param = Config::get_value(ConfigSearchIndex::QUERY_PARAMETER);
00073 return $page_data->get_get()->get_item($param, '');
00074 }
00075 }